php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #48413 floating-point formats on 64 bit systems
Submitted: 2009-05-28 12:41 UTC Modified: 2009-06-05 01:00 UTC
Votes:4
Avg. Score:4.8 ± 0.4
Reproduced:3 of 3 (100.0%)
Same Version:0 (0.0%)
Same OS:3 (100.0%)
From: vgabor at gmail dot com Assigned:
Status: No Feedback Package: Math related
PHP Version: 5.2.9 OS: Linux x86_64
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: vgabor at gmail dot com
New email:
PHP Version: OS:

 

 [2009-05-28 12:41 UTC] 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";



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-05-28 16:43 UTC] jani@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 16:43 UTC] jani@php.net
And when you post example scripts, put <?php ?> tags around and also provide the expected / actual outputs.
 [2009-06-05 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 16 17:01:30 2024 UTC