php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #68797 Number 2.2250738585072012e-308 converted incorrectly
Submitted: 2015-01-11 00:53 UTC Modified: 2015-03-25 15:06 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: exploringbinary at gmail dot com Assigned: ab (profile)
Status: Closed Package: Math related
PHP Version: 5.5.20 OS: Windows
Private report: No CVE-ID: None
 [2015-01-11 00:53 UTC] 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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-01-12 16:39 UTC] ab@php.net
-Status: Open +Status: Verified
 [2015-01-12 16:39 UTC] 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-03-17 23:58 UTC] ab@php.net
-Status: Verified +Status: Closed -Assigned To: +Assigned To: ab
 [2015-03-17 23:58 UTC] 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-03-25 14:32 UTC] 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-25 15:06 UTC] 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-04-01 01:25 UTC] exploringbinary at gmail dot com
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.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 10:01:29 2024 UTC