public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libc/16151] New: strtod() incorrectly rounds 2^-1075 to 0x0.0000000000001p-1022
@ 2013-11-11 4:06 exploringbinary at gmail dot com
2013-11-11 18:29 ` [Bug libc/16151] " jsm28 at gcc dot gnu.org
` (6 more replies)
0 siblings, 7 replies; 8+ messages in thread
From: exploringbinary at gmail dot com @ 2013-11-11 4:06 UTC (permalink / raw)
To: glibc-bugs
https://sourceware.org/bugzilla/show_bug.cgi?id=16151
Bug ID: 16151
Summary: strtod() incorrectly rounds 2^-1075 to
0x0.0000000000001p-1022
Product: glibc
Version: 2.18
Status: NEW
Severity: minor
Priority: P2
Component: libc
Assignee: unassigned at sourceware dot org
Reporter: exploringbinary at gmail dot com
CC: drepper.fsp at gmail dot com
Given the decimal string that represents 2^-1075, strtod() returns an
incorrectly rounded result: it returns 0x0.0000000000001p-1022 instead of the
correct answer, 0x0p+0 (zero). 2^-1075 is half the smallest double precision
value, 2^-1074.
I did a little tracing to help isolate the bug. It appears that the division is
correct and that this is just a rounding problem. In /stdlib/strtod_l.c,
round_and_return() calls round_away() with half_bit == true, last_digit_odd ==
false, and more_bits == true. This causes it to round up (case FE_TONEAREST).
more_bits should be false, which would make it round correctly to even.
This program demonstrates the problem:
#include <stdio.h>
#include <stdlib.h>
int main (void)
{
double d =
strtod("0.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000024703282292062327208828439643411068618252990130716238221279284125033775363510437593264991818081799618989828234772285886546332835517796989819938739800539093906315035659515570226392290858392449105184435931802849936536152500319370457678249219365623669863658480757001585769269903706311928279558551332927834338409351978015531246597263579574622766465272827220056374006485499977096599470454020828166226237857393450736339007967761930577506740176324673600968951340535537458516661134223766678604162159680461914467291840300530057530849048765391711386591646239524912623653881879636239373280423891018672348497668235089863388587925628302755995657524455507255189313690836254779186948667994968324049705821028513185451396213837722826145437693412532098591327667236328125",NULL);
printf("%a\n",d);
}
(I used PARI/GP to generate that string: 2.^-1075)
(I am submitting this bug report on behalf of Water Qian, who discovered this
bug and reported it on my blog:
http://www.exploringbinary.com/how-glibc-strtod-works/#comment-6892 .)
--
You are receiving this mail because:
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug libc/16151] strtod() incorrectly rounds 2^-1075 to 0x0.0000000000001p-1022
2013-11-11 4:06 [Bug libc/16151] New: strtod() incorrectly rounds 2^-1075 to 0x0.0000000000001p-1022 exploringbinary at gmail dot com
@ 2013-11-11 18:29 ` jsm28 at gcc dot gnu.org
2013-11-11 18:41 ` jsm28 at gcc dot gnu.org
` (5 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: jsm28 at gcc dot gnu.org @ 2013-11-11 18:29 UTC (permalink / raw)
To: glibc-bugs
https://sourceware.org/bugzilla/show_bug.cgi?id=16151
Joseph Myers <jsm28 at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |ASSIGNED
Assignee|unassigned at sourceware dot org |jsm28 at gcc dot gnu.org
--- Comment #1 from Joseph Myers <jsm28 at gcc dot gnu.org> ---
Testing a patch. This only applies to input that is exactly (plus or minus)
half the least subnormal and only if an entire normal mantissa fits in one MP
limb; in that case, the loop testing for extra bits set in the MANT_DIG initial
mantissa bits should have i < RETURN_LIMB_SIZE - 1 not RETURN_LIMB_SIZE (the
loop for the multiple-limb case has the correct bound).
--
You are receiving this mail because:
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug libc/16151] strtod() incorrectly rounds 2^-1075 to 0x0.0000000000001p-1022
2013-11-11 4:06 [Bug libc/16151] New: strtod() incorrectly rounds 2^-1075 to 0x0.0000000000001p-1022 exploringbinary at gmail dot com
2013-11-11 18:29 ` [Bug libc/16151] " jsm28 at gcc dot gnu.org
@ 2013-11-11 18:41 ` jsm28 at gcc dot gnu.org
2013-11-12 16:48 ` exploringbinary at gmail dot com
` (4 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: jsm28 at gcc dot gnu.org @ 2013-11-11 18:41 UTC (permalink / raw)
To: glibc-bugs
https://sourceware.org/bugzilla/show_bug.cgi?id=16151
--- Comment #2 from Joseph Myers <jsm28 at gcc dot gnu.org> ---
(Actually, "only if an entire normal mantissa fits in one MP limb" is not a
condition for this bug; the following loop for shifts of more than one limb is
for other cases, but gets the loop bound right.)
--
You are receiving this mail because:
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug libc/16151] strtod() incorrectly rounds 2^-1075 to 0x0.0000000000001p-1022
2013-11-11 4:06 [Bug libc/16151] New: strtod() incorrectly rounds 2^-1075 to 0x0.0000000000001p-1022 exploringbinary at gmail dot com
2013-11-11 18:29 ` [Bug libc/16151] " jsm28 at gcc dot gnu.org
2013-11-11 18:41 ` jsm28 at gcc dot gnu.org
@ 2013-11-12 16:48 ` exploringbinary at gmail dot com
2013-11-13 13:01 ` cvs-commit at gcc dot gnu.org
` (3 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: exploringbinary at gmail dot com @ 2013-11-12 16:48 UTC (permalink / raw)
To: glibc-bugs
https://sourceware.org/bugzilla/show_bug.cgi?id=16151
--- Comment #3 from Rick Regan <exploringbinary at gmail dot com> ---
For reference, my slightly more refined description of the problem is here:
http://www.exploringbinary.com/glibc-strtod-incorrectly-converts-2-to-the-negative-1075/
.
--
You are receiving this mail because:
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug libc/16151] strtod() incorrectly rounds 2^-1075 to 0x0.0000000000001p-1022
2013-11-11 4:06 [Bug libc/16151] New: strtod() incorrectly rounds 2^-1075 to 0x0.0000000000001p-1022 exploringbinary at gmail dot com
` (2 preceding siblings ...)
2013-11-12 16:48 ` exploringbinary at gmail dot com
@ 2013-11-13 13:01 ` cvs-commit at gcc dot gnu.org
2013-11-13 13:02 ` jsm28 at gcc dot gnu.org
` (2 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2013-11-13 13:01 UTC (permalink / raw)
To: glibc-bugs
http://sourceware.org/bugzilla/show_bug.cgi?id=16151
--- Comment #4 from cvs-commit at gcc dot gnu.org <cvs-commit at gcc dot gnu.org> ---
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU C Library master sources".
The branch, master has been updated
via 9310c284ae91f13247c9dd7ff58fc2683b9c523d (commit)
from 7a2ad8cf392acfcaef319e722dda9101d4d8b6bd (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=9310c284ae91f13247c9dd7ff58fc2683b9c523d
commit 9310c284ae91f13247c9dd7ff58fc2683b9c523d
Author: Joseph Myers <joseph@codesourcery.com>
Date: Wed Nov 13 12:59:54 2013 +0000
Fix strtod rounding of half the least subnormal (bug 16151).
-----------------------------------------------------------------------
Summary of changes:
ChangeLog | 9 ++
NEWS | 3 +-
stdlib/strtod_l.c | 2 +-
stdlib/tst-strtod-round-data | 8 ++
stdlib/tst-strtod-round.c | 288 ++++++++++++++++++++++++++++++++++++++++++
5 files changed, 308 insertions(+), 2 deletions(-)
--
You are receiving this mail because:
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug libc/16151] strtod() incorrectly rounds 2^-1075 to 0x0.0000000000001p-1022
2013-11-11 4:06 [Bug libc/16151] New: strtod() incorrectly rounds 2^-1075 to 0x0.0000000000001p-1022 exploringbinary at gmail dot com
` (3 preceding siblings ...)
2013-11-13 13:01 ` cvs-commit at gcc dot gnu.org
@ 2013-11-13 13:02 ` jsm28 at gcc dot gnu.org
2013-11-13 14:15 ` exploringbinary at gmail dot com
2014-06-13 9:33 ` fweimer at redhat dot com
6 siblings, 0 replies; 8+ messages in thread
From: jsm28 at gcc dot gnu.org @ 2013-11-13 13:02 UTC (permalink / raw)
To: glibc-bugs
https://sourceware.org/bugzilla/show_bug.cgi?id=16151
Joseph Myers <jsm28 at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution|--- |FIXED
--- Comment #5 from Joseph Myers <jsm28 at gcc dot gnu.org> ---
Fixed for 2.19.
--
You are receiving this mail because:
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug libc/16151] strtod() incorrectly rounds 2^-1075 to 0x0.0000000000001p-1022
2013-11-11 4:06 [Bug libc/16151] New: strtod() incorrectly rounds 2^-1075 to 0x0.0000000000001p-1022 exploringbinary at gmail dot com
` (4 preceding siblings ...)
2013-11-13 13:02 ` jsm28 at gcc dot gnu.org
@ 2013-11-13 14:15 ` exploringbinary at gmail dot com
2014-06-13 9:33 ` fweimer at redhat dot com
6 siblings, 0 replies; 8+ messages in thread
From: exploringbinary at gmail dot com @ 2013-11-13 14:15 UTC (permalink / raw)
To: glibc-bugs
https://sourceware.org/bugzilla/show_bug.cgi?id=16151
--- Comment #6 from Rick Regan <exploringbinary at gmail dot com> ---
Thanks. I tested it and it works.
--
You are receiving this mail because:
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug libc/16151] strtod() incorrectly rounds 2^-1075 to 0x0.0000000000001p-1022
2013-11-11 4:06 [Bug libc/16151] New: strtod() incorrectly rounds 2^-1075 to 0x0.0000000000001p-1022 exploringbinary at gmail dot com
` (5 preceding siblings ...)
2013-11-13 14:15 ` exploringbinary at gmail dot com
@ 2014-06-13 9:33 ` fweimer at redhat dot com
6 siblings, 0 replies; 8+ messages in thread
From: fweimer at redhat dot com @ 2014-06-13 9:33 UTC (permalink / raw)
To: glibc-bugs
https://sourceware.org/bugzilla/show_bug.cgi?id=16151
Florian Weimer <fweimer at redhat dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Flags| |security-
--
You are receiving this mail because:
You are on the CC list for the bug.
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2014-06-13 9:33 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-11-11 4:06 [Bug libc/16151] New: strtod() incorrectly rounds 2^-1075 to 0x0.0000000000001p-1022 exploringbinary at gmail dot com
2013-11-11 18:29 ` [Bug libc/16151] " jsm28 at gcc dot gnu.org
2013-11-11 18:41 ` jsm28 at gcc dot gnu.org
2013-11-12 16:48 ` exploringbinary at gmail dot com
2013-11-13 13:01 ` cvs-commit at gcc dot gnu.org
2013-11-13 13:02 ` jsm28 at gcc dot gnu.org
2013-11-13 14:15 ` exploringbinary at gmail dot com
2014-06-13 9:33 ` fweimer at redhat dot com
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).