Edit report at http://bugs.php.net/bug.php?id=54994&edit=1
ID: 54994 Updated by: [email protected] Reported by: technique at ircf dot fr Summary: Weird float values on increment -Status: Open +Status: Bogus Type: Bug Package: Math related Operating System: Linux Ubuntu PHP 5.3.5-1ubuntu7 PHP Version: 5.3SVN-2011-06-04 (snap) Block user comment: N Private report: N New Comment: Floating point values have a limited precision. Hence a value might not have the same string representation after any processing. That also includes writing a floating point value in your script and directly printing it without any mathematical operations. If you would like to know more about "floats" and what IEEE 754 is, read this: http://www.floating-point-gui.de/ Thank you for your interest in PHP. The number of expected decimals is given by your precision ini setting. Previous Comments: ------------------------------------------------------------------------ [2011-06-04 17:01:11] technique at ircf dot fr Description: ------------ PHP produces much more decimals than expected when a variable is incremented in a for loop. On my computer, it happens around [54,66] and [84,100]. This might be related to the http://bugs.php.net/bug.php?id=50095 bug. Test script: --------------- for($i=0;$i<100;$i+=0.1) echo "$i\n"; Expected result: ---------------- 0 0.1 0.2 ... 99.8 99.9 Actual result: -------------- 0 0.1 0.2 ... 54 54.1 54.200000000001 54.300000000001 ... 66.300000000001 66.400000000001 66.5 66.6 ... 83.9 84 84.099999999999 84.199999999999 ... 99.899999999999 99.999999999999 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/bug.php?id=54994&edit=1
