Edit report at https://bugs.php.net/bug.php?id=51396&edit=1
ID: 51396
Updated by: requinix@php.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:
@sandino: That's not the original bug, nor is it a bug at all. It's the unfortunate nature
of floating-point numbers. http://www.floating-point-gui.de/
Previous Comments:
------------------------------------------------------------------------
[2016-06-12 04:32:21] sandino at sandino dot net
<?php
/* This one is better */
ini_set("precision",17); /* changed precision from 16 to 17 */
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 --version
PHP 5.5.35-pl0-gentoo (cli) (built: May 13 2016 22:17:08)
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2015 Zend Technologies
with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2015, by Zend Technologies
php test.php
-0.089999999999999997
-0.099000000000000005
-0.099900000000000003
-0.099989999999999996
-0.099999000000000005
-0.099999900000000003
-0.099999989999999997
-0.099999999000000006
-0.099999999899999997
-0.099999999990000005
-0.099999999999
-0.099999999999900002
-0.09999999999999
-0.099999999999999006
-0.099999999999999895
-0.099999999999999992
-0.10000000000000001
-0.10000000000000001
-0.10000000000000001
-0.10000000000000001
-0.10000000000000001
*/
?>
------------------------------------------------------------------------
[2016-06-12 04:28:27] sandino at sandino dot net
<?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
*/
?>
------------------------------------------------------------------------
[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.
------------------------------------------------------------------------
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