Bug #68797 [Com]: Number 2.2250738585072012e-308 converted incorrectly
| From: | exploringbinary at gmail dot com | Date: | Wed, 01 Apr 2015 01:25:31 +0000 |
| Subject: | Bug #68797 [Com]: Number 2.2250738585072012e-308 converted incorrectly | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-191758@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=68797&edit=1
ID: 68797
Comment by: exploringbinary at gmail dot com
Reported by: exploringbinary at gmail dot com
Summary: Number 2.2250738585072012e-308 converted incorrectly
Status: Closed
Type: Bug
Package: Math related
Operating System: Windows
PHP Version: 5.5.20
Assigned To: ab
Block user comment: N
Private report: N
New Comment:
I still couldn't find the description of the fix but I can tell from the new zend_strtod.c that
the fix was to refresh it with the latest copy of David Gay's dtoa.c (with PHP-specific
enhancements merged in).
I have not tested it but plan to at some point. Thanks.
Previous Comments:
------------------------------------------------------------------------
[2015-03-25 15:06:31] ab@php.net
@exploringbinary, yes, the fix was put into master, you can easly check and clone it from github. It
is also noted in the NEWS. A windows binary can be fetched from the link in my previous post or
directly http://windows.php.net/downloads/snaps/master/
.
Thanks.
------------------------------------------------------------------------
[2015-03-25 14:32:59] exploringbinary at gmail dot com
Hi,
Can you point me to the changed source code (zend_strtod.c presumably)? http://snaps.php.net/ is a dead link. I don't see this bug in
any of the change logs. Can you provide a description of the fix as well? Thanks.
------------------------------------------------------------------------
[2015-03-17 23:58:41] ab@php.net
The fix for this bug has been committed.
Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
For Windows:
http://windows.php.net/snapshots/
Thank you for the report, and for helping us make PHP better.
Should be fixed in master now, please check.
Thanks.
------------------------------------------------------------------------
[2015-01-12 16:39:28] ab@php.net
I can reproduce this. But from what I see on the internets like here http://patrakov.blogspot.de/2009/03/dont-use-old-dtoac.html
the version you point to can possibly have issues with gcc. Lets see if there's a commit
history somewhere for that file.
Thanks.
------------------------------------------------------------------------
[2015-01-11 00:53:10] exploringbinary at gmail dot com
Description:
------------
The conversion of the number 2.2250738585072012e-308 (equivalent to DBL_MIN) to double-precision
floating-point is done incorrectly; it is one ULP too low. It prints back as
2.2250738585072009E-308; it should be 2.2250738585072014e-308 (DBL_MIN).
(The nearby decimal numbers 2.2250738585072013e-308, 2.2250738585072014e-308,
2.2250738585072015e-308, and 2.2250738585072016e-308 all convert correctly to DBL_MIN.)
This is likely due to PHP's old copy of David Gay's dtoa.c; see these change entries at http://www.netlib.org/fp/changes -- they are probably
what is needed:
Wed Feb 12 00:40:01 EST 1997
dtoa.c: strtod: on IEEE systems, scale to avoid intermediate
underflows when the result does not underflow; compiling with
-DNO_IEEE_Scale restores the old logic. Fix a bug, revealed by
input string 2.2250738585072012e-308, in treating input just less
than the smallest normalized number. (The bug introduced an extra
ULP of error in this special case.)
Fri May 15 07:49:07 EDT 1998
dtoa.c: strtod: fix another glitch with scaling to avoid underflow
with IEEE arithmetic, again revealed by the input string
2.2250738585072012e-308, which was rounded to the largest denormal
rather than the smallest normal double precision number.
Test script:
---------------
<?php ini_set("precision", "17"); echo 2.2250738585072012e-308; ?>
Expected result:
----------------
2.2250738585072014e-308
Actual result:
--------------
2.2250738585072009E-308
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=68797&edit=1