Req #64323 [NEW]: Float inconsistency between echo/var_dump and tests

From: Date: Thu, 28 Feb 2013 14:27:44 +0000
Subject: Req #64323 [NEW]: Float inconsistency between echo/var_dump and tests
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-177458@lists.php.net to get a copy of this message
From: guaycuru at gmail dot com Operating system: Any PHP version: 5.4.12 Package: Scripting Engine problem Bug Type: Feature/Change Request Bug description:Float inconsistency between echo/var_dump and tests Description: ------------ So, I know that due to the way computers store float numbers, we end up with some oddities. This BUG is NOT about that. Instead, I found some inconsistencies on how PHP handle that, and it's easy to think of cases that those inconsistencies would end up causing lots of wasted hours debugging. Please see test script, it should be pretty self explanatory. My change request is that, since float / echo deal with that inconsistency (rounding 0.3000000000000000444089209850062616169452667236328125 to 0.3), so should control flow functions like IF, WHILE, etc... Tested on PHP 5.3.22 and PHP 5.4.12 Test script: --------------- <?php $a = 0.1; $b = 0.2; var_dump($a + $b); if($a + $b <= 0.3) echo "All is right in the universe!"; else echo "Something is wrong here!"; ?> Expected result: ---------------- float(0.3) All is right in the universe! Also, this result is acceptable: float(0.3000000000000000444089209850062616169452667236328125) Something is wrong here! Actual result: -------------- float(0.3) Something is wrong here! -- Edit bug report at https://bugs.php.net/bug.php?id=64323&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=64323&r=trysnapshot54 Try a snapshot (PHP 5.3): https://bugs.php.net/fix.php?id=64323&r=trysnapshot53 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=64323&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=64323&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=64323&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=64323&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=64323&r=needscript Try newer version: https://bugs.php.net/fix.php?id=64323&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=64323&r=support Expected behavior: https://bugs.php.net/fix.php?id=64323&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=64323&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=64323&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=64323&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=64323&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=64323&r=dst IIS Stability: https://bugs.php.net/fix.php?id=64323&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=64323&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=64323&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=64323&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=64323&r=mysqlcfg

« previous php.bugs (#177458) next »