From: Paul Eggert Date: Sun, 6 Jul 2025 19:33:06 +0000 (-0700) Subject: float-h-tests: port to C23 PowerPC GCC X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=55a366a06fbd98bf13adc531579e3513cee97a32;p=thirdparty%2Fgnulib.git float-h-tests: port to C23 PowerPC GCC Problem reported by C. Neidhal . * 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. --- diff --git a/ChangeLog b/ChangeLog index 286d589d23..df445d4b76 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2025-07-06 Paul Eggert + + float-h-tests: port to C23 PowerPC GCC + Problem reported by C. Neidhal + . + * 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 pagealign_alloc: Don't assume pointers fit in 'unsigned long'. diff --git a/modules/float-h-tests b/modules/float-h-tests index 6ebf0b5f31..3ac3532501 100644 --- a/modules/float-h-tests +++ b/modules/float-h-tests @@ -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@ diff --git a/tests/test-float-h.c b/tests/test-float-h.c index b1246f6193..c0440bc3f0 100644 --- a/tests/test-float-h.c +++ b/tests/test-float-h.c @@ -101,6 +101,8 @@ long double ls = LDBL_SNAN; /* added in ISO C 23 */ /* ------------------------------------------------------------------------- */ +#include + #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); }