From: Paul Eggert Date: Sun, 6 Jul 2025 23:22:05 +0000 (-0700) Subject: float-h: port to C23 PowerPC GCC X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=65ed9d3b24ad09fd61d326c83e7f1b05f6e9d65f;p=thirdparty%2Fgnulib.git float-h: port to C23 PowerPC GCC * lib/float.in.h (LDBL_MAX) [__LDBL_NORM_MAX__]: Do not override, as GCC versions defining __LDBL_NORM_MAX__ surely have LDBL_MAX right. (LDBL_NORM_MAX): Prefer __LDBL_NORM_MAX__ if defined. Otherwise, hardcode PowerPC value if applicable. * tests/test-float-h.c (normalize_long_double): Fix typo that broke this function when given large numbers. (test_long_double): Normalize LDBL_MAX before comparing it to LDBL_NORM_MAX. --- diff --git a/ChangeLog b/ChangeLog index df445d4b76..998838c98f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,8 +1,14 @@ 2025-07-06 Paul Eggert float-h-tests: port to C23 PowerPC GCC - Problem reported by C. Neidhal - . + Problems reported by C. Neidhal in: + https://lists.gnu.org/r/bug-gnulib/2025-07/msg00021.html + https://lists.gnu.org/r/bug-gnulib/2025-07/msg00027.html + * lib/float.in.h (LDBL_MAX): Do not override on PowerPC + if __LDBL_NORM_MAX__ is defined, as GCC versions defining that + symbol surely have LDBL_MAX right. + (LDBL_NORM_MAX): Prefer __LDBL_NORM_MAX__ if defined. + Otherwise, hardcode PowerPC value if applicable. * 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. diff --git a/lib/float.in.h b/lib/float.in.h index 54093f6e7e..86af55ad1b 100644 --- a/lib/float.in.h +++ b/lib/float.in.h @@ -124,7 +124,7 @@ extern const union gl_long_double_union gl_LDBL_MAX; # undef LDBL_MIN # define LDBL_MIN 2.22507385850720138309023271733240406422e-308L /* DBL_MIN = 2^-1022 */ #endif -#if (defined _ARCH_PPC || defined _POWER) && (defined _AIX || defined __linux__) && (LDBL_MANT_DIG == 106) && defined __GNUC__ +#if (defined _ARCH_PPC || defined _POWER) && (defined _AIX || defined __linux__) && (LDBL_MANT_DIG == 106) && defined __GNUC__ && !defined __LDBL_NORM_MAX__ # undef LDBL_MAX /* LDBL_MAX is represented as { 0x7FEFFFFF, 0xFFFFFFFF, 0x7C8FFFFF, 0xFFFFFFFF }. It is not easy to define: @@ -309,7 +309,13 @@ extern gl_DBL_SNAN_t gl_DBL_SNAN; # endif #endif #ifndef LDBL_NORM_MAX -# define LDBL_NORM_MAX LDBL_MAX +# ifdef __LDBL_NORM_MAX__ +# define LDBL_NORM_MAX __LDBL_NORM_MAX__ +# elif FLT_RADIX == 2 && LDBL_MAX_EXP == 1024 && LDBL_MANT_DIG == 106 +# define LDBL_NORM_MAX 8.98846567431157953864652595394501E+307L +# else +# define LDBL_NORM_MAX LDBL_MAX +# endif #endif #ifndef LDBL_SNAN /* For sh, beware of . */ diff --git a/tests/test-float-h.c b/tests/test-float-h.c index c0440bc3f0..1e294c87e0 100644 --- a/tests/test-float-h.c +++ b/tests/test-float-h.c @@ -412,7 +412,7 @@ normalize_long_double (long double volatile x) { int xexp; long double volatile xfrac = frexpl (x, &xexp); - x = ldexpl (floorl (ldexpl (xfrac, LDBL_MANT_DIG - xexp)), + x = ldexpl (floorl (ldexpl (xfrac, LDBL_MANT_DIG)), xexp - LDBL_MANT_DIG); } else @@ -510,7 +510,7 @@ test_long_double (void) #endif /* Check the value of LDBL_NORM_MAX. */ - ASSERT (LDBL_NORM_MAX == LDBL_MAX); + ASSERT (LDBL_NORM_MAX == normalize_long_double (LDBL_MAX)); /* Check the value of LDBL_SNAN. */ ASSERT (isnanl (LDBL_SNAN));