From:             vgabor at gmail dot com
Operating system: Linux x86_64
PHP version:      5.2.9
PHP Bug Type:     Math related
Bug description:  floating-point formats on 64 bit systems

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 bug report at http://bugs.php.net/?id=48413&edit=1
-- 
Try a CVS snapshot (PHP 5.2):        
http://bugs.php.net/fix.php?id=48413&r=trysnapshot52
Try a CVS snapshot (PHP 5.3):        
http://bugs.php.net/fix.php?id=48413&r=trysnapshot53
Try a CVS snapshot (PHP 6.0):        
http://bugs.php.net/fix.php?id=48413&r=trysnapshot60
Fixed in CVS:                        
http://bugs.php.net/fix.php?id=48413&r=fixedcvs
Fixed in CVS and need be documented: 
http://bugs.php.net/fix.php?id=48413&r=needdocs
Fixed in release:                    
http://bugs.php.net/fix.php?id=48413&r=alreadyfixed
Need backtrace:                      
http://bugs.php.net/fix.php?id=48413&r=needtrace
Need Reproduce Script:               
http://bugs.php.net/fix.php?id=48413&r=needscript
Try newer version:                   
http://bugs.php.net/fix.php?id=48413&r=oldversion
Not developer issue:                 
http://bugs.php.net/fix.php?id=48413&r=support
Expected behavior:                   
http://bugs.php.net/fix.php?id=48413&r=notwrong
Not enough info:                     
http://bugs.php.net/fix.php?id=48413&r=notenoughinfo
Submitted twice:                     
http://bugs.php.net/fix.php?id=48413&r=submittedtwice
register_globals:                    
http://bugs.php.net/fix.php?id=48413&r=globals
PHP 4 support discontinued:          http://bugs.php.net/fix.php?id=48413&r=php4
Daylight Savings:                    http://bugs.php.net/fix.php?id=48413&r=dst
IIS Stability:                       
http://bugs.php.net/fix.php?id=48413&r=isapi
Install GNU Sed:                     
http://bugs.php.net/fix.php?id=48413&r=gnused
Floating point limitations:          
http://bugs.php.net/fix.php?id=48413&r=float
No Zend Extensions:                  
http://bugs.php.net/fix.php?id=48413&r=nozend
MySQL Configuration Error:           
http://bugs.php.net/fix.php?id=48413&r=mysqlcfg

Reply via email to