ID: 48413 Updated by: j...@php.net Reported By: vgabor at gmail dot com Status: Feedback Bug Type: Math related Operating System: Linux x86_64 PHP Version: 5.2.9 New Comment:
And when you post example scripts, put <?php ?> tags around and also provide the expected / actual outputs. Previous Comments: ------------------------------------------------------------------------ [2009-05-28 16:43:12] j...@php.net Please try using this CVS snapshot: http://snaps.php.net/php5.3-latest.tar.gz For Windows: http://windows.php.net/snapshots/ ------------------------------------------------------------------------ [2009-05-28 12:41:27] vgabor at gmail dot com Description: ------------ This in not quite bug, I think everybody know well the possible float-integer conversation problems on the usual 32 bit systems, but the 64 bit systems give us some new ones. On 64 bit, the float becomes actually less precise then the integer, because the binary64 (double) floating point format what the PHP using is up to 52+1 bits while the integer 63+1 bit. Most of the mathematical functions are using and convert the numbers to float which historically give better result on 32 bit system (52+1 bit versus 31+1 bit) but with 64 bit integer thats unfortunately not the case (52+1 bit instead of 63+1 bit) Solving this problem I would recommend to introduce in the PHP the binary128 (quad) floating point format from the latest floating-point arithmetic standard (IEEE 754-2008, last year) which would give us 112+1 bits precision. Reproduce code: --------------- Just a quick example when it comes to numbers above 52+1 bit (the / operator convert the result to float which leads to precision loss on 64 bit systems): ini_set('precision', 99); $X=449999999985476582; $Y=449999999985476608; echo "($X/10*10) === $X: ".((int)($X/10*10) === $X ? 'true' : 'false')."\n"; echo "($X/10*10) === $Y: ".((int)($X/10*10) === $Y ? 'true' : 'false')."\n\n"; echo ($X)."\n"; echo ($X/10)."\n"; echo ($X/10*10)."\n"; ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=48413&edit=1