Req #72239 [NEW]: float zero should be equal int 0 even with ===

From: Date: Thu, 19 May 2016 02:45:49 +0000
Subject: Req #72239 [NEW]: float zero should be equal int 0 even with ===
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-201186@lists.php.net to get a copy of this message
From:             dosergio at gmail dot com
Operating system: all
PHP version:      Irrelevant
Package:          *General Issues
Bug Type:         Feature/Change Request
Bug description:float zero should be equal int 0 even with ===

Description:
------------
Zero is zero, I think there is no "float flavour" of zero and "int
flavour" of zero since zero is nothing.

Why to check data type when both sides are absolute ZERO ?

So for the comparison 0 === 0.0, I think PHP should go beyound the
memory/way of storing the number, and consider that we are comparing two
absolute zero values, so the result could be TRUE as it is in other
languages.

The data type check only makes sense to enter in scene when one of the
compared values differ from zero!
 
What makes a factual float? One number like 0.0000000000001 ! I mean,
different from zero.

The problem: 
A programmer knows that a value in some condition is zero.
But when comparing  if ($myValue === 0) causes failure, since PHP
obliges you to write if ($myValue === 0.0) 


 



Test script:
---------------
$x = floatVal(0);

if( $x === 0){ // why to check data type when both sides are ZERO ?
  echo 'Will not enter here, php expects 0.0';
} else {
  echo '0 and 0.0 is the same "VALUE"';
}


-- 
Edit bug report at https://bugs.php.net/bug.php?id=72239&edit=1
-- 
Try a snapshot (PHP 5.4):   https://bugs.php.net/fix.php?id=72239&r=trysnapshot54
Try a snapshot (PHP 5.5):   https://bugs.php.net/fix.php?id=72239&r=trysnapshot55
Try a snapshot (trunk):     https://bugs.php.net/fix.php?id=72239&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=72239&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=72239&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=72239&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=72239&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=72239&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=72239&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=72239&r=notwrong
Not enough info:            https://bugs.php.net/fix.php?id=72239&r=notenoughinfo
Submitted twice:            https://bugs.php.net/fix.php?id=72239&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=72239&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=72239&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=72239&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=72239&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=72239&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=72239&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=72239&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=72239&r=mysqlcfg



Thread (6 messages)

« previous php.bugs (#201186) next »