Edit report at https://bugs.php.net/bug.php?id=51396&edit=1
ID: 51396
Comment by: sandino at sandino dot net
Reported by: codeslinger at compsalot dot com
Summary: Math is Unreliable
Status: Not a bug
Type: Bug
Package: Math related
Operating System: any
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
<?php
ini_set("precision",16);
echo (string) (double) -0.09;
echo "\n";
echo (string) (double) -0.099;
echo "\n";
echo (string) (double) -0.0999;
echo "\n";
echo (string) (double) -0.09999;
echo "\n";
echo (string) (double) -0.099999;
echo "\n";
echo (string) (double) -0.0999999;
echo "\n";
echo (string) (double) -0.09999999;
echo "\n";
echo (string) (double) -0.099999999;
echo "\n";
echo (string) (double) -0.0999999999;
echo "\n";
echo (string) (double) -0.09999999999;
echo "\n";
echo (string) (double) -0.099999999999;
echo "\n";
echo (string) (double) -0.0999999999999;
echo "\n";
echo (string) (double) -0.09999999999999;
echo "\n";
echo (string) (double) -0.099999999999999;
echo "\n";
echo (string) (double) -0.0999999999999999;
echo "\n";
echo (string) (double) -0.09999999999999999;
echo "\n";
echo (string) (double) -0.099999999999999999;
echo "\n";
echo (string) (double) -0.0999999999999999999;
echo "\n";
echo (string) (double) -0.09999999999999999999;
echo "\n";
echo (string) (double) -0.099999999999999999999;
echo "\n";
echo (string) (double) -0.0999999999999999999999;
echo "\n";
/* Seems like something is still broken:
php test.php
-0.09
-0.099
-0.0999
-0.09999
-0.099999
-0.0999999
-0.09999999
-0.09999999900000001
-0.0999999999
-0.09999999999
-0.099999999999
-0.0999999999999
-0.09999999999999
-0.09999999999999901
-0.09999999999999989
-0.09999999999999999
-0.1
-0.1
-0.1
-0.1
-0.1
*/
?>
Previous Comments:
------------------------------------------------------------------------
[2010-05-24 14:29:26] codeslinger at compsalot dot com
Pajoye
Please take a look at #43487 this appears to be where the Mandriva Devs landed their change.
Quote:
"as peroyvind found, the miscompilation is inside Zend/zend_strtod.c,
and -no-ftree-vrp workaround the bug."
Unfortunately that change does not appear to have done the trick. This thing is dang hard to
reproduce, short of running through every possible 58 digit number, or getting really lucky with
random numbers, I can't see how to reliably test this.
------------------------------------------------------------------------
[2010-05-24 14:14:53] pajoye@php.net
And please use latest 5.3 or 5.2, from our downloads (only).
------------------------------------------------------------------------
[2010-05-24 14:04:53] codeslinger at compsalot dot com
P.S. Please note that in my own testing I have verified that the presence or absence of the xdebug
and zend debug extensions do not alter the behavior of this bug, this was verified on Windows.
Also note how for instance 5.2.4 fails on Windows and on Ubuntu but works on Mandriva (or at least
was not found to fail on Mandriva).
Also I can tell you from my own testing that the specific values which fail on Windows are very
different from the specific values which fail on Unbuntu, when tested on the same computer. The
only thing which can be said with some level of confidence is that all of the failures involve
numbers with the digit 9 in them. Since these are 58? digit numbers and only a very few specific
values fail, the potential to NOT see a failure is huge.
------------------------------------------------------------------------
[2010-05-24 13:59:45] pajoye@php.net
Please read my last comment and provide the info I asked there. Without that, there is not a chance
to get anywhere regarding this issue.
------------------------------------------------------------------------
[2010-05-24 13:46:10] codeslinger at compsalot dot com
In Summary: As Reported by Multiple People
Windows XP (32 bit) PHP 5.2.4 Fails
Windows XP (32 bit) PHP 5.2.5 Works
Windows 2000 (32 bit) PHP 5.2.5 Works
Windows XP (32 bit) PHP 5.2.9 Fails
Windows 2000 (32 bit) PHP 5.2.9 Fails
Windows 2000 (32 bit) PHP 5.2.11 Fails
Windows 2003 (?? bit) PHP 5.2.12 Fails
Windows 2003 (?? bit) PHP 5.2.13 Fails
Ubuntu 8 (32bit) PHP 5.2.4 Fails
Ubuntu 8 (32bit) PHP 5.2.9 (custom build) Works
Ubuntu 9 (64bit) PHP 5.2.10 Works
Mandriva 2008 (32bit & 64bit) PHP 5.2.4 Works
Mandriva 2008 (32bit & 64bit) Unpatched PHP 5.2.5 Fails
This bug has been reported by multiple people. The above list is the combination of my own testing
plus what I found reported by other people. The windows oses are all using the STOCK BUILD as
provided by php.net
It is very important to understand that the specific values which fail are highly variable. A
specific value which fails on one os/php version does not necessarily fail on a different
combination of os+php, but a different value will fail instead.
It is also important to realize that given the obscurity and variability of this bug, just because a
particular version of php is reported as working, does not guarantee that the bug does not exist, it
only says that so far no one has reported encountering a specific value which triggers this bug.
All of the following are thought to influence the specific behavior and reproducibility of this bug.
The number of cpu bits
The operating system
The specific version of php
The compiler flags that were used to build php
The "precision" setting for php
The format specifier/precision in an sprintf statement
sprintf versus implied (string) conversion
It is also possible that the floating point hardware could have an influence on the reproducibility
of this bug.
Since the WORK-AROUND did not work for John, it would appear that we still have a problem which
needs to be solved.
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=51396
--
Edit this bug report at https://bugs.php.net/bug.php?id=51396&edit=1