]> Savannah Git Hosting - gnulib.git/commitdiff
strtof, strtod, strtold: Set errno upon gradual underflow.
authorBruno Haible <bruno@clisp.org>
Tue, 23 Jul 2024 08:39:28 +0000 (10:39 +0200)
committerBruno Haible <bruno@clisp.org>
Mon, 12 Aug 2024 15:30:12 +0000 (17:30 +0200)
* lib/strtod.c (scale_radix_exp): If the result is a denormalized
number, set errno to ERANGE.

ChangeLog
lib/strtod.c

index 8d0924ebe6e827000443bc0d9ae75aca11be2f2f..f4958a1d664b7a11c6deee97da545c07efaefcba 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2024-07-23  Bruno Haible  <bruno@clisp.org>
+
+       strtof, strtod, strtold: Set errno upon gradual underflow.
+       * lib/strtod.c (scale_radix_exp): If the result is a denormalized
+       number, set errno to ERANGE.
+
 2024-07-21  Bruno Haible  <bruno@clisp.org>
 
        bootstrap: Avoid failure when gnulib-tool removed gettext.m4.
index e218a46f7163a65a92133c8abc9be748f69646dc..8847cae9409863e8d36a5e5cff18e38cd8282c08 100644 (file)
@@ -158,11 +158,20 @@ scale_radix_exp (DOUBLE x, int radix, long int exponent)
         {
           if (e < 0)
             {
-              while (e++ != 0)
+              for (;;)
                 {
+                  if (e++ == 0)
+                    {
+                      if (r < MIN && r > -MIN)
+                        /* Gradual underflow, resulting in a denormalized
+                           number.  */
+                        errno = ERANGE;
+                      break;
+                    }
                   r /= radix;
-                  if (r == 0 && x != 0)
+                  if (r == 0)
                     {
+                      /* Flush-to-zero underflow.  */
                       errno = ERANGE;
                       break;
                     }