]> Savannah Git Hosting - gnulib.git/commitdiff
xstrtod, xstrtold: Don't treat gradual underflow as an error.
authorBruno Haible <bruno@clisp.org>
Wed, 24 Jul 2024 17:46:44 +0000 (19:46 +0200)
committerBruno Haible <bruno@clisp.org>
Wed, 24 Jul 2024 17:48:47 +0000 (19:48 +0200)
* lib/xstrtod.c (XSTRTOD): Upon gradual underflow, return true with
errno = 0.
* lib/xstrtod.h (xstrtod, xstrtold): Update specification.
* tests/test-xstrtod.c (main): For gradual underflow, expect ok &&
errno == 0.
* tests/test-xstrtold.c (main): Likewise.

ChangeLog
lib/xstrtod.c
lib/xstrtod.h
tests/test-xstrtod.c
tests/test-xstrtold.c

index 3e9d691efadca4c7887f0d7e459329535b948d81..a96c219d7e6fc33736f1ecdc601735f7e94bf64e 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2024-07-24  Bruno Haible  <bruno@clisp.org>
+
+       xstrtod, xstrtold: Don't treat gradual underflow as an error.
+       * lib/xstrtod.c (XSTRTOD): Upon gradual underflow, return true with
+       errno = 0.
+       * lib/xstrtod.h (xstrtod, xstrtold): Update specification.
+       * tests/test-xstrtod.c (main): For gradual underflow, expect ok &&
+       errno == 0.
+       * tests/test-xstrtold.c (main): Likewise.
+
 2024-07-23  Collin Funk  <collin.funk1@gmail.com>
 
        Detect UNIX domain sockets supported by recent Windows versions.
index a9ca7e8d107a05c7bb8258c24bc88af2a5a934e0..7565658e4dd5947a6a201208880e04e04bce1ce1 100644 (file)
@@ -57,11 +57,18 @@ XSTRTOD (char const *str, char const **ptr, DOUBLE *result,
   else
     {
       /* Flag overflow as an error.
-         Flag gradual underflow as an error.
+         Flag gradual underflow as no error.
          Flag flush-to-zero underflow as no error.
          In either case, the caller can inspect *RESULT to get more details.  */
       if (val != 0 && errno == ERANGE)
-        ok = false;
+        {
+          if (val >= 1 || val <= -1)
+            /* Overflow.  */
+            ok = false;
+          else
+            /* Gradual underflow.  */
+            errno = 0;
+        }
     }
 
   if (ptr != NULL)
index 8ceca6c433d261b4fcc9e55340a246960899a810..f6a1ed888a1106c188c3ce79f5a04876b72ea5a9 100644 (file)
@@ -42,8 +42,7 @@ extern "C" {
    NaN                                                true    NaN         0
    ±Infinity                                          true    ±HUGE_VAL   0
    overflow                                           false   ±HUGE_VAL   ERANGE
-   gradual underflow [!MSVC]                          false   near zero   ERANGE
-   gradual underflow [MSVC]                           true    near zero   0
+   gradual underflow                                  true    near zero   0
    flush-to-zero underflow                            true    ±0.0        ERANGE
    other finite value                                 true    value       0
 
@@ -68,8 +67,7 @@ bool xstrtod (const char *str, const char **ptr, double *result,
    NaN                                                true    NaN         0
    ±Infinity                                          true    ±HUGE_VALL  0
    overflow                                           false   ±HUGE_VALL  ERANGE
-   gradual underflow [!MSVC]                          false   near zero   ERANGE
-   gradual underflow [MSVC]                           true    near zero   0
+   gradual underflow                                  true    near zero   0
    flush-to-zero underflow                            true    ±0.0L       ERANGE
    other finite value                                 true    value       0
 
index 3464120f1ece1a4cbee6cfe97c3f65fb7c40b740..e02d97203ad04485f1d31792c7c54946a0db8924 100644 (file)
@@ -658,36 +658,20 @@ main ()
     const char *ptr;
     double result = UNINIT;
     bool ok = xstrtod (input, &ptr, &result, strtod);
-#if defined _MSC_VER
     ASSERT (ok);
-#else
-    ASSERT (!ok);
-#endif
     ASSERT (0.0 < result && result <= DBL_MIN);
     ASSERT (ptr == input + 6);
-#if defined _MSC_VER
     ASSERT (errno == 0);
-#else
-    ASSERT (errno == ERANGE);
-#endif
   }
   {
     const char input[] = "-1e-320";
     const char *ptr;
     double result = UNINIT;
     bool ok = xstrtod (input, &ptr, &result, strtod);
-#if defined _MSC_VER
     ASSERT (ok);
-#else
-    ASSERT (!ok);
-#endif
     ASSERT (-DBL_MIN <= result && result < 0.0);
     ASSERT (ptr == input + 7);
-#if defined _MSC_VER
     ASSERT (errno == 0);
-#else
-    ASSERT (errno == ERANGE);
-#endif
   }
 
   /* Flush-to-zero underflow.  */
index b83e78067bdaa67abd4d4d8c3c48a83d794fd54a..a8788ca100c8fbca1943cc1fa7f83c4ba090dfbd 100644 (file)
@@ -662,18 +662,10 @@ main ()
     const char *ptr;
     long double result = UNINIT;
     bool ok = xstrtold (input, &ptr, &result, strtold);
-#if defined _MSC_VER
     ASSERT (ok);
-#else
-    ASSERT (!ok);
-#endif
     ASSERT (0.0L < result && result <= LDBL_MIN);
     ASSERT (ptr == input + strlen (input));
-#if defined _MSC_VER
     ASSERT (errno == 0);
-#else
-    ASSERT (errno == ERANGE);
-#endif
   }
   {
 #if LDBL_MAX_EXP > 10000
@@ -684,18 +676,10 @@ main ()
     const char *ptr;
     long double result = UNINIT;
     bool ok = xstrtold (input, &ptr, &result, strtold);
-#if defined _MSC_VER
     ASSERT (ok);
-#else
-    ASSERT (!ok);
-#endif
     ASSERT (-LDBL_MIN <= result && result < 0.0L);
     ASSERT (ptr == input + strlen (input));
-#if defined _MSC_VER
     ASSERT (errno == 0);
-#else
-    ASSERT (errno == ERANGE);
-#endif
   }
 
   /* Flush-to-zero underflow.  */