This is the mail archive of the glibc-bugs@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug libc/5995] New: strtod and negative underflow


POSIX requires strtod("-1e-100000",NULL) to return a value whose magnitude is no
larger than the smallest normalized number (as well as requiring errno to be set
to ERANGE).  glibc currently meets the strict requirement by returning 0.0, but
this is a poor choice in the face of quality of implementation.  Most other
functions that run into underflow situations at least preserve the sign, on the
assumption that the sign is important (consider, for example,
pow(-1,strtod(str,NULL)), where the wrong sign leads to the wrong infinity).  A
one-line patch should be sufficient:

2008-03-29  Eric Blake  <ebb9@byu.net>

	* stdlib/strtod_l.c (____STRTOF_INTERNAL): Preserve sign on underflow.

Index: stdlib/strtod_l.c
===================================================================
RCS file: /cvs/glibc/libc/stdlib/strtod_l.c,v
retrieving revision 1.28
diff -u -p -b -r1.28 strtod_l.c
--- stdlib/strtod_l.c	8 Mar 2008 21:31:55 -0000	1.28
+++ stdlib/strtod_l.c	29 Mar 2008 16:15:27 -0000
@@ -1028,7 +1028,7 @@ ____STRTOF_INTERNAL (nptr, endptr, group
   if (__builtin_expect (exponent < MIN_10_EXP - (DIG + 1), 0))
     {
       __set_errno (ERANGE);
-      return 0.0;
+      return negative ? -0.0 : 0.0;
     }
 
   if (int_no > 0)

-- 
           Summary: strtod and negative underflow
           Product: glibc
           Version: 2.4
            Status: NEW
          Severity: normal
          Priority: P2
         Component: libc
        AssignedTo: drepper at redhat dot com
        ReportedBy: ebb9 at byu dot net
                CC: glibc-bugs at sources dot redhat dot com


http://sourceware.org/bugzilla/show_bug.cgi?id=5995

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]