]> git.ipfire.org Git - thirdparty/gnulib.git/commitdiff
float-h: Enforce the ISO C 23 compliant value for LDBL_EPSILON.
authorBruno Haible <bruno@clisp.org>
Mon, 7 Jul 2025 15:02:45 +0000 (17:02 +0200)
committerBruno Haible <bruno@clisp.org>
Mon, 7 Jul 2025 15:02:45 +0000 (17:02 +0200)
Reported by Cosima Neidahl <opna2608@protonmail.com> in
<https://lists.gnu.org/archive/html/bug-gnulib/2025-07/msg00021.html>.

* lib/float.in.h (LDBL_EPSILON): Override on all PowerPC platforms.

ChangeLog
lib/float.in.h

index 9d62b1615ea75381c4fb5c00b29862f7b445a6d4..d09840c10db51d8b4b284caa3b4bb47161dd726f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2025-07-07  Bruno Haible  <bruno@clisp.org>
+
+       float-h: Enforce the ISO C 23 compliant value for LDBL_EPSILON.
+       Reported by Cosima Neidahl <opna2608@protonmail.com> in
+       <https://lists.gnu.org/archive/html/bug-gnulib/2025-07/msg00021.html>.
+       * lib/float.in.h (LDBL_EPSILON): Override on all PowerPC platforms.
+
 2025-07-07  Bruno Haible  <bruno@clisp.org>
 
        vasnprintf: Fix -Wswitch-unreachable warning.
index 86af55ad1bd09723ff42b22fee7bdd9c5b0ce323..4759e83478b4f0cfa61bc72abc93f7fe0f609bc4 100644 (file)
@@ -181,6 +181,21 @@ extern const union gl_long_double_union gl_LDBL_MAX;
 # endif
 #endif
 
+/* On PowerPC platforms, 'long double' has a double-double representation.
+   Up to ISO C 17, this was outside the scope of ISO C because it can represent
+   numbers with mantissas of the form 1.<52 bits><many zeroes><52 bits>, such as
+   1.0L + 4.94065645841246544176568792868221e-324L = 1 + 2^-1074; see
+   ISO C 17 § 5.2.4.2.2.(3).
+   In ISO C 23, wording has been included that makes this 'long double'
+   representation compliant; see ISO C 23 § 5.2.5.3.3.(8)-(9).  In this setting,
+   numbers with mantissas of the form 1.<52 bits><many zeroes><52 bits> are
+   called "unnormalized".  And since LDBL_EPSILON must be normalized (per
+   ISO C 23 § 5.2.5.3.3.(33)), it must be 2^-105.  */
+#if defined __powerpc__ && LDBL_MANT_DIG == 106
+# undef LDBL_EPSILON
+# define LDBL_EPSILON 2.46519032881566189191165176650870696773e-32L /* 2^-105 */
+#endif
+
 /* ============================ ISO C11 support ============================ */
 
 /* 'float' properties */