From: Operating system: Linux PHP version: 5.3.10 Package: Math related Bug Type: Bug Bug description:Wrong division of float numbers
Description: ------------ --- >From manual page: http://www.php.net/function.floor#refsect1-function.floor-description --- I encountered problem when dividing float numbers. It's simple formula which can be solved by 10 year old child. But not by PHP! See example. The problem is that displayed value (3) doesn't correspond with internal value 2.999999999999999 and floor() then returns 2 which is obviously incorrect result! And that's serious problem. The same code in C returns correct numbers. Test script: --------------- <?php $a = 1.2; $b = 0.4; $v = $a / $b; printf("v(15) = %.15f\n", $v); printf("v(16) = %.16f\n", $v); print "v = $v\n"; print "floor(v) = ".floor($v)."\n"; ?> Expected result: ---------------- v(15) = 3.000000000000000 v(16) = 3.0000000000000000 v = 3 floor(v) = 3 Actual result: -------------- v(15) = 3.000000000000000 v(16) = 2.9999999999999996 v = 3 floor(v) = 2 -- Edit bug report at https://bugs.php.net/bug.php?id=61855&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=61855&r=trysnapshot54 Try a snapshot (PHP 5.3): https://bugs.php.net/fix.php?id=61855&r=trysnapshot53 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=61855&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=61855&r=fixed Fixed in SVN and need be documented: https://bugs.php.net/fix.php?id=61855&r=needdocs Fixed in release: https://bugs.php.net/fix.php?id=61855&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=61855&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=61855&r=needscript Try newer version: https://bugs.php.net/fix.php?id=61855&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=61855&r=support Expected behavior: https://bugs.php.net/fix.php?id=61855&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=61855&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=61855&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=61855&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=61855&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=61855&r=dst IIS Stability: https://bugs.php.net/fix.php?id=61855&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=61855&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=61855&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=61855&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=61855&r=mysqlcfg