Edit report at https://bugs.php.net/bug.php?id=64674&edit=1
ID: 64674 Comment by: phpmpan at mpan dot pl Reported by: guillaume dot loire at cnrs dot fr Summary: Calculation error with ceil Status: Open Type: Bug Package: Math related Operating System: Linux debian Squeeze PHP Version: Irrelevant Block user comment: N Private report: N New Comment: The result is perfectly fine and expected. Please read about floating point numbers, operations on them and their usage. Ceiling of 880.0000000000001136868377216160297393798828125, which is the result of multiplying 8.8 by 1.0 by 100, is in fact 881. Also note that real numbers ceiling operation makes sense only for a tiny subset of all floating point numbers. For most of inputs there is either no result possible at all or relative difference between input and the result is too small to be considered important. Previous Comments: ------------------------------------------------------------------------ [2013-04-19 09:26:38] guillaume dot loire at cnrs dot fr Description: ------------ Hello, I found a calculation error with ceil function. When doing a calculation such as this : ceil(8.80*1.00*100) it returns 881 instead of 880. While doing ceil(880) it returns (as it should) 880. I think this error occurs when running ceil function cumulative with calculation and not with a single number. I wrote a little script to identify if others numbers are impacted and i found theses ones when running it from 10 to 10000, but there may be other. Test script: --------------- <?php for ($i = 10; $i <= 10000; $i+=10) { $toto=ceil(($i/100*1.00)*100); if (preg_match( '/1$/',$toto)) { echo $toto."<br>"; } } ?> Expected result: ---------------- 110 220 440 490 830 880 930 980 1610 1660 1710 1760 1810 1860 1910 1960 2010 3220 3270 3320 3370 3420 3470 3520 3570 3620 3670 3720 3770 3820 3870 3920 3970 4020 4070 6440 6490 6540 6590 6640 6690 6740 6790 6840 6890 6940 6990 7040 7090 7140 7190 7240 7290 7340 7390 7440 7490 7540 7590 7640 7690 7740 7790 7840 7890 7940 7990 8040 8090 8140 8190 Actual result: -------------- 111 221 441 491 831 881 931 981 1611 1661 1711 1761 1811 1861 1911 1961 2011 3221 3271 3321 3371 3421 3471 3521 3571 3621 3671 3721 3771 3821 3871 3921 3971 4021 4071 6441 6491 6541 6591 6641 6691 6741 6791 6841 6891 6941 6991 7041 7091 7141 7191 7241 7291 7341 7391 7441 7491 7541 7591 7641 7691 7741 7791 7841 7891 7941 7991 8041 8091 8141 8191 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=64674&edit=1