|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2009-05-28 16:43 UTC] jani@php.net
[2009-05-28 16:43 UTC] jani@php.net
[2009-06-05 01:00 UTC] php-bugs at lists dot php dot net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 13:00:02 2025 UTC |
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";