This is the mail archive of the
glibc-bugs@sourceware.org
mailing list for the glibc project.
[Bug libc/16151] New: strtod() incorrectly rounds 2^-1075 to 0x0.0000000000001p-1022
- From: "exploringbinary at gmail dot com" <sourceware-bugzilla at sourceware dot org>
- To: glibc-bugs at sourceware dot org
- Date: Mon, 11 Nov 2013 04:06:04 +0000
- Subject: [Bug libc/16151] New: strtod() incorrectly rounds 2^-1075 to 0x0.0000000000001p-1022
- Auto-submitted: auto-generated
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.