]> git.ipfire.org Git - thirdparty/gnulib.git/commitdiff
float-h-tests: port to C23 PowerPC GCC
authorPaul Eggert <eggert@cs.ucla.edu>
Sun, 6 Jul 2025 19:33:06 +0000 (12:33 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Sun, 6 Jul 2025 19:33:42 +0000 (12:33 -0700)
Problem reported by C. Neidhal
<https://lists.gnu.org/r/bug-gnulib/2025-07/msg00021.html>.
* modules/float-h-tests (Depends-on): Add floorl, frexpl, ldexpl.
(test_float_h_LDADD): Link the resulting libms too.
* tests/test-float-h.c: Include math.h.
(normalize_long_double): New function.
(test_long_double): Use it.

ChangeLog
modules/float-h-tests
tests/test-float-h.c

index 286d589d23d042c9c68a63034de98bf2249fec63..df445d4b76d619c909b0269ab4fffcc14f672d0a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2025-07-06  Paul Eggert  <eggert@cs.ucla.edu>
+
+       float-h-tests: port to C23 PowerPC GCC
+       Problem reported by C. Neidhal
+       <https://lists.gnu.org/r/bug-gnulib/2025-07/msg00021.html>.
+       * modules/float-h-tests (Depends-on): Add floorl, frexpl, ldexpl.
+       (test_float_h_LDADD): Link the resulting libms too.
+       * tests/test-float-h.c: Include math.h.
+       (normalize_long_double): New function.
+       (test_long_double): Use it.
+
 2025-07-06  Collin Funk  <collin.funk1@gmail.com>
 
        pagealign_alloc: Don't assume pointers fit in 'unsigned long'.
index 6ebf0b5f31926c007987ffae9926132b4c8b8bf5..3ac353250109197806161bb0072103c39fe35aed 100644 (file)
@@ -5,6 +5,9 @@ tests/macros.h
 Depends-on:
 fpieee
 fpucw
+floorl
+frexpl
+ldexpl
 isnanf-nolibm
 isnand-nolibm
 isnanl-nolibm
@@ -15,3 +18,4 @@ configure.ac:
 Makefile.am:
 TESTS += test-float-h
 check_PROGRAMS += test-float-h
+test_float_h_LDADD = $(LDADD) @FLOORL_LIBM@ @FREXPL_LIBM@ @LDEXPL_LIBM@
index b1246f61938ab85311b173251fc35617f3b5c193..c0440bc3f0d0f157b06ead1151642226d97e83d8 100644 (file)
@@ -101,6 +101,8 @@ long double ls = LDBL_SNAN; /* added in ISO C 23 */
 
 /* ------------------------------------------------------------------------- */
 
+#include <math.h>
+
 #include "fpucw.h"
 #include "isnanf-nolibm.h"
 #include "isnand-nolibm.h"
@@ -396,6 +398,30 @@ test_double (void)
 
 /* -------------------- Check macros for 'long double' -------------------- */
 
+/* Return X after normalization.  This makes a difference on PowerPC
+   platforms where long double uses a "double double" format that does
+   not conform to the C23 rules for floating point.  On such a platform,
+   FLT_RADIX = 2, LDBL_MANT_DIG = 106, LDBL_EPSILON = 2**-105, and
+   1 < 1 + e < 1 + LDBL_EPSILON, where e = 2**-106 and 1 + e is a
+   representable long double value that is not normalized.
+   On such a platform, normalize_long_double (1 + e) returns 1.  */
+static long double
+normalize_long_double (long double volatile x)
+{
+  if (FLT_RADIX == 2)
+    {
+      int xexp;
+      long double volatile xfrac = frexpl (x, &xexp);
+      x = ldexpl (floorl (ldexpl (xfrac, LDBL_MANT_DIG - xexp)),
+                  xexp - LDBL_MANT_DIG);
+    }
+  else
+    {
+      /* Hope that X is already normalized.  */
+    }
+  return x;
+}
+
 static void
 test_long_double (void)
 {
@@ -455,7 +481,7 @@ test_long_double (void)
     for (n = 0; n <= 2 * LDBL_MANT_DIG; n++)
       {
         volatile long double half_n = pow2l (- n); /* 2^-n */
-        volatile long double x = me - half_n;
+        volatile long double x = normalize_long_double (me - half_n);
         if (x < me)
           ASSERT (x <= 1.0L);
       }