Edit report at https://bugs.php.net/bug.php?id=55518&edit=1
ID: 55518 User updated by: forez84 at gmail dot com Reported by: forez84 at gmail dot com Summary: for loop incorrect arithmetic iteration Status: Open Type: Bug Package: Math related Operating System: Ubuntu -PHP Version: 5.3SVN-2011-08-27 (SVN) +PHP Version: PHP Version 5.3.5-1ubuntu7.2 Block user comment: N Private report: N New Comment: <?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 than it should. Previous Comments: ------------------------------------------------------------------------ [2011-08-27 06:53:02] forez84 at gmail dot com 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 this bug report at https://bugs.php.net/bug.php?id=55518&edit=1