|  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
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
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.
Bug Type:
From: exploringbinary at gmail dot com
New email:
PHP Version: OS:


 [2015-01-11 00:53 UTC] exploringbinary at gmail dot com
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 -- 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:

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2015-01-12 16:39 UTC]
-Status: Open +Status: Verified
 [2015-01-12 16:39 UTC]
I can reproduce this. But from what I see on the internets like here the version you point to can possibly have issues with gcc. Lets see if there's a commit history somewhere for that file.

 [2015-03-17 23:58 UTC]
-Status: Verified +Status: Closed -Assigned To: +Assigned To: ab
 [2015-03-17 23:58 UTC]
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

 For Windows:
Thank you for the report, and for helping us make PHP better.

Should be fixed in master now, please check.

 [2015-03-25 14:32 UTC] exploringbinary at gmail dot com

Can you point me to the changed source code (zend_strtod.c presumably)? 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]
@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 .

 [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 May 23 19:01:38 2024 UTC