]> Savannah Git Hosting - gnulib.git/commitdiff
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 17:04:02 +0000 (19:04 +0200)
* lib/strtod.c (scale_radix_exp): If the result is a denormalized
number, set errno to ERANGE.

ChangeLog
lib/strtod.c

index 7484d325ea2e44b1d8425eefd266739724a4529a..0b91b6639249013be9fa77145ac2d63f7ecb7a34 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2024-07-23  Bruno Haible  <bruno@clisp.org>
+
+       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 62e2b870fc9c9d4f893b5656f93b878bca5021ea..7a8136b201496409f85ecb45ba10a6e008d2fe53 100644 (file)
@@ -141,11 +141,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;
                     }