Bug 14046 - strtof returns incorrectly-rounded results
Summary: strtof returns incorrectly-rounded results
Status: RESOLVED DUPLICATE of bug 3479
Alias: None
Product: glibc
Classification: Unclassified
Component: libc (show other bugs)
Version: unspecified
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-05-02 02:06 UTC by Rich Felker
Modified: 2014-06-25 11:09 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:
fweimer: security-


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Rich Felker 2012-05-02 02:06:57 UTC
Test case:

"0.000000000000000000000000000000000000000000002101947696487225606385594374934874196920392912814773657635602425834686624028790902229957282543182373046875"

This is the decimal value of 0x1.8p-149, the value exactly halfway between the smallest two positive single-precision floating point values. It has more than DECIMAL_DIG significant digits, so it should round as follows:

"If the subject sequence D has the decimal form and more than DECIMAL_DIG significant digits, consider the two bounding, adjacent decimal strings L and U, both having DECIMAL_DIG significant digits, such that the values of L, D, and U satisfy L <= D <= U. The result should be one of the (equal or adjacent) values that would be obtained by correctly rounding L and U according to the current rounding direction, with the extra stipulation that the error with respect to D should have a correct sign for the current rounding direction."

Here L="0.00000000000000000000000000000000000000000000210194769648722560638" and U="0.00000000000000000000000000000000000000000000210194769648722560639". Correctly rounded, they should be 0x1p-149 and 0x1p-148, respectively, but strtof rounds all three (D,L,U) to 0x1p-149.

This is just the particular case I thought to check; surely there are many others, possibly without even going into the denormal range (which was the first place I thought to look for bugs).
Comment 1 Joseph Myers 2012-05-02 10:00:53 UTC
This is a known issue.

*** This bug has been marked as a duplicate of bug 3479 ***