Merge commit 'a39d4083cab589d7cd6a13e8a4b8db8875261d75'
[gnulib.git] / lib / strtod.c
index cd61add..e554a84 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991-1992, 1997, 1999, 2003, 2006, 2008-2010 Free Software
+/* Copyright (C) 1991-1992, 1997, 1999, 2003, 2006, 2008-2014 Free Software
    Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify
    Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify
@@ -31,9 +31,6 @@
 #ifndef HAVE_LDEXP_IN_LIBC
 #define HAVE_LDEXP_IN_LIBC 0
 #endif
 #ifndef HAVE_LDEXP_IN_LIBC
 #define HAVE_LDEXP_IN_LIBC 0
 #endif
-#ifndef HAVE_RAW_DECL_STRTOD
-#define HAVE_RAW_DECL_STRTOD 0
-#endif
 
 /* Return true if C is a space in the current locale, avoiding
    problems with signed char and isspace.  */
 
 /* Return true if C is a space in the current locale, avoiding
    problems with signed char and isspace.  */
@@ -149,7 +146,7 @@ parse_number (const char *nptr,
       else
         {
           /* The value of the digit doesn't matter, since we have already
       else
         {
           /* The value of the digit doesn't matter, since we have already
-             gotten as many digits as can be represented in a `double'.
+             gotten as many digits as can be represented in a 'double'.
              This doesn't necessarily mean the result will overflow.
              The exponent may reduce it to within range.
 
              This doesn't necessarily mean the result will overflow.
              The exponent may reduce it to within range.
 
@@ -193,7 +190,7 @@ static double underlying_strtod (const char *, char **);
 /* HP cc on HP-UX 10.20 has a bug with the constant expression -0.0.
    ICC 10.0 has a bug when optimizing the expression -zero.
    The expression -DBL_MIN * DBL_MIN does not work when cross-compiling
 /* HP cc on HP-UX 10.20 has a bug with the constant expression -0.0.
    ICC 10.0 has a bug when optimizing the expression -zero.
    The expression -DBL_MIN * DBL_MIN does not work when cross-compiling
-   to PowerPC on MacOS X 10.5.  */
+   to PowerPC on Mac OS X 10.5.  */
 #if defined __hpux || defined __sgi || defined __ICC
 static double
 compute_minus_zero (void)
 #if defined __hpux || defined __sgi || defined __ICC
 static double
 compute_minus_zero (void)
@@ -303,6 +300,7 @@ strtod (const char *nptr, char **endptr)
           && c_tolower (s[4]) == 'y')
         s += 5;
       num = HUGE_VAL;
           && c_tolower (s[4]) == 'y')
         s += 5;
       num = HUGE_VAL;
+      errno = saved_errno;
     }
   else if (c_tolower (*s) == 'n'
            && c_tolower (s[1]) == 'a'
     }
   else if (c_tolower (*s) == 'n'
            && c_tolower (s[1]) == 'a'
@@ -325,6 +323,7 @@ strtod (const char *nptr, char **endptr)
          to interpreting n-char-sequence as a hexadecimal number.  */
       if (s != end)
         num = NAN;
          to interpreting n-char-sequence as a hexadecimal number.  */
       if (s != end)
         num = NAN;
+      errno = saved_errno;
     }
   else
     {
     }
   else
     {
@@ -342,24 +341,11 @@ strtod (const char *nptr, char **endptr)
   return negative ? -num : num;
 }
 
   return negative ? -num : num;
 }
 
-/* The "underlying" strtod implementation.  This must be defined
+/* The underlying strtod implementation.  This must be defined
    after strtod because it #undefs strtod.  */
 static double
 underlying_strtod (const char *nptr, char **endptr)
 {
    after strtod because it #undefs strtod.  */
 static double
 underlying_strtod (const char *nptr, char **endptr)
 {
-  if (HAVE_RAW_DECL_STRTOD)
-    {
-      /* Prefer the native strtod if available.  Usually it should
-         work and it should give more-accurate results than our
-         approximation.  */
-      #undef strtod
-      return strtod (nptr, endptr);
-    }
-  else
-    {
-      /* Approximate strtod well enough for this module.  There's no
-         need to handle anything but finite unsigned decimal
-         numbers with nonnull ENDPTR.  */
-      return parse_number (nptr, 10, 10, 1, 'e', endptr);
-    }
+#undef strtod
+  return strtod (nptr, endptr);
 }
 }