From: Operating system: Ubuntu PHP version: 5.3SVN-2011-08-27 (SVN) Package: Math related Bug Type: Bug Bug description:for loop incorrect arithmetic iteration
Description: ------------ <?php for ($i=0; $i<100; $i=$i+0.1) { echo $i.'|'; } ?> this produces something like: 0|0.1|0.2|0.3|0.4|0.5|0.6|0.7|0.8|0.9... ...53.6|53.7|53.8|53.9|54|54.1|54.200000000001|54.300000000001|54.400000000001|54.500000000001|... ...66.200000000001|66.300000000001|66.400000000001|66.5|66.6|66.7|66.8|66.9|67|67.1|67.2|... ...83.7|83.8|83.9|84|84.099999999999|84.199999999999|84.299999999999... ...99.799999999999|99.899999999999|99.999999999999| I believe it makes one more iteration then it should. Test script: --------------- <?php for ($i=0; $i<100; $i=$i+0.1) { echo $i.'|'; } ?> Expected result: ---------------- 0|0.1|0.2|0.3|...53.9|54|54.1|54.2|54.3|54.4|...99.9| -- Edit bug report at https://bugs.php.net/bug.php?id=55518&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=55518&r=trysnapshot54 Try a snapshot (PHP 5.3): https://bugs.php.net/fix.php?id=55518&r=trysnapshot53 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=55518&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=55518&r=fixed Fixed in SVN and need be documented: https://bugs.php.net/fix.php?id=55518&r=needdocs Fixed in release: https://bugs.php.net/fix.php?id=55518&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=55518&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=55518&r=needscript Try newer version: https://bugs.php.net/fix.php?id=55518&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=55518&r=support Expected behavior: https://bugs.php.net/fix.php?id=55518&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=55518&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=55518&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=55518&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=55518&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=55518&r=dst IIS Stability: https://bugs.php.net/fix.php?id=55518&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=55518&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=55518&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=55518&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=55518&r=mysqlcfg