Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
at devShellTools-shell 230 lines 9.6 kB view raw
1Applies the following incremental gnulib commits: 2 3- 55a366a06fbd98bf13adc531579e3513cee97a32 4- 65ed9d3b24ad09fd61d326c83e7f1b05f6e9d65f 5- ce8e9de0bf34bc63dffc67ab384334c509175f64 6- 6164b4cb0887b5331a4e64449107decd37d32735 7 8With adjustments specific to the structure & differences in coreutils: 9 10- gnulib code is split across lib and gnulib-tests 11- A Makefile.in is used for the test flags instead of the fancy automake modules 12 in the upstream gnulib project, so we add -lm to the float test there. 13 Surrounding texts in this file are slightly different in every project. 14--- 15diff '--color=auto' -ruN a/gnulib-tests/Makefile.in b/gnulib-tests/Makefile.in 16--- a/gnulib-tests/Makefile.in 2025-04-09 10:05:54.000000000 +0000 17+++ b/gnulib-tests/Makefile.in 2025-07-09 10:00:23.767927263 +0000 18@@ -1496,7 +1496,7 @@ 19 $(am__DEPENDENCIES_1) 20 test_float_h_SOURCES = test-float-h.c 21 test_float_h_OBJECTS = test-float-h.$(OBJEXT) 22-test_float_h_LDADD = $(LDADD) 23+test_float_h_LDADD = $(LDADD) -lm 24 test_float_h_DEPENDENCIES = libtests.a ../lib/libcoreutils.a \ 25 libtests.a ../lib/libcoreutils.a libtests.a \ 26 $(am__DEPENDENCIES_1) 27diff '--color=auto' -ruN a/gnulib-tests/test-float-h.c b/gnulib-tests/test-float-h.c 28--- a/gnulib-tests/test-float-h.c 2025-01-01 09:32:30.000000000 +0000 29+++ b/gnulib-tests/test-float-h.c 2025-07-09 10:00:13.837937094 +0000 30@@ -101,6 +101,8 @@ 31 32 /* ------------------------------------------------------------------------- */ 33 34+#include <math.h> 35+ 36 #include "fpucw.h" 37 #include "isnanf-nolibm.h" 38 #include "isnand-nolibm.h" 39@@ -396,6 +398,44 @@ 40 41 /* -------------------- Check macros for 'long double' -------------------- */ 42 43+static int 44+test_isfinitel (long double volatile x) 45+{ 46+ if (x != x) 47+ return 0; 48+ long double volatile zero = x * 0; 49+ return zero == 0; 50+} 51+ 52+/* Return X after normalization. This makes a difference on platforms 53+ where long double can represent unnormalized values. For example, 54+ suppose x = 1 + 2**-106 on PowerPC with IBM long double where 55+ FLT_RADIX = 2, LDBL_MANT_DIG = 106, and LDBL_EPSILON = 2**-105. 56+ Then 1 < x < 1 + LDBL_EPSILON, and normalize_long_double (x) returns 1. */ 57+static long double 58+normalize_long_double (long double volatile x) 59+{ 60+ if (FLT_RADIX == 2 && test_isfinitel (x)) 61+ { 62+ int xexp; 63+ long double volatile 64+ frac = frexpl (x, &xexp), 65+ significand = frac * pow2l (LDBL_MANT_DIG), 66+ normalized_significand = truncl (significand), 67+ normalized_x = normalized_significand * pow2l (xexp - LDBL_MANT_DIG); 68+ 69+ /* The test_isfinitel defends against PowerPC with IBM long double, 70+ which fritzes out near LDBL_MAX. */ 71+ if (test_isfinitel (normalized_x)) 72+ x = normalized_x; 73+ } 74+ else 75+ { 76+ /* Hope that X is already normalized. */ 77+ } 78+ return x; 79+} 80+ 81 static void 82 test_long_double (void) 83 { 84@@ -455,7 +495,7 @@ 85 for (n = 0; n <= 2 * LDBL_MANT_DIG; n++) 86 { 87 volatile long double half_n = pow2l (- n); /* 2^-n */ 88- volatile long double x = me - half_n; 89+ volatile long double x = normalize_long_double (me - half_n); 90 if (x < me) 91 ASSERT (x <= 1.0L); 92 } 93@@ -483,8 +523,12 @@ 94 ASSERT (!LDBL_IS_IEC_60559); 95 #endif 96 97+ printf("LDBL_NORM_MAX: %LF\n", LDBL_NORM_MAX); 98+ printf("LDBL_MAX: %LF\n", LDBL_MAX); 99+ printf("normalize_long_double(LDBL_MAX): %LF\n", normalize_long_double(LDBL_MAX)); 100+ 101 /* Check the value of LDBL_NORM_MAX. */ 102- ASSERT (LDBL_NORM_MAX == LDBL_MAX); 103+ ASSERT (LDBL_NORM_MAX == normalize_long_double (LDBL_MAX)); 104 105 /* Check the value of LDBL_SNAN. */ 106 ASSERT (isnanl (LDBL_SNAN)); 107diff '--color=auto' -ruN a/lib/float.c b/lib/float.c 108--- a/lib/float.c 2025-01-01 09:32:29.000000000 +0000 109+++ b/lib/float.c 2025-07-09 10:00:13.837937094 +0000 110@@ -23,7 +23,7 @@ 111 #if GNULIB_defined_long_double_union 112 # if (defined _ARCH_PPC || defined _POWER) && (defined _AIX || defined __linux__) && (LDBL_MANT_DIG == 106) && defined __GNUC__ 113 const union gl_long_double_union gl_LDBL_MAX = 114- { { DBL_MAX, DBL_MAX / (double)134217728UL / (double)134217728UL } }; 115+ { { DBL_MAX, DBL_MAX / 0x1p53 } }; 116 # elif defined __i386__ 117 const union gl_long_double_union gl_LDBL_MAX = 118 { { 0xFFFFFFFF, 0xFFFFFFFF, 32766 } }; 119diff '--color=auto' -ruN a/lib/float.in.h b/lib/float.in.h 120--- a/lib/float.in.h 2025-01-01 09:32:29.000000000 +0000 121+++ b/lib/float.in.h 2025-07-09 10:00:13.837937094 +0000 122@@ -113,44 +113,38 @@ 123 # define LDBL_MAX_10_EXP 4932 124 #endif 125 126-/* On AIX 7.1 with gcc 4.2, the values of LDBL_MIN_EXP, LDBL_MIN, LDBL_MAX are 127- wrong. 128- On Linux/PowerPC with gcc 4.4, the value of LDBL_MAX is wrong. */ 129-#if (defined _ARCH_PPC || defined _POWER) && defined _AIX && (LDBL_MANT_DIG == 106) && defined __GNUC__ 130+/* On PowerPC with gcc 15 when using __ibm128 long double, the value of 131+ LDBL_MIN_EXP, LDBL_MIN, LDBL_MAX, and LDBL_NORM_MAX are wrong. */ 132+#if ((defined _ARCH_PPC || defined _POWER) && LDBL_MANT_DIG == 106 \ 133+ && defined __GNUC__) 134 # undef LDBL_MIN_EXP 135 # define LDBL_MIN_EXP DBL_MIN_EXP 136 # undef LDBL_MIN_10_EXP 137 # define LDBL_MIN_10_EXP DBL_MIN_10_EXP 138 # undef LDBL_MIN 139 # define LDBL_MIN 2.22507385850720138309023271733240406422e-308L /* DBL_MIN = 2^-1022 */ 140-#endif 141-#if (defined _ARCH_PPC || defined _POWER) && (defined _AIX || defined __linux__) && (LDBL_MANT_DIG == 106) && defined __GNUC__ 142 # undef LDBL_MAX 143-/* LDBL_MAX is represented as { 0x7FEFFFFF, 0xFFFFFFFF, 0x7C8FFFFF, 0xFFFFFFFF }. 144- It is not easy to define: 145- #define LDBL_MAX 1.79769313486231580793728971405302307166e308L 146- is too small, whereas 147- #define LDBL_MAX 1.79769313486231580793728971405302307167e308L 148- is too large. Apparently a bug in GCC decimal-to-binary conversion. 149- Also, I can't get values larger than 150- #define LDBL63 ((long double) (1ULL << 63)) 151- #define LDBL882 (LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63) 152- #define LDBL945 (LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63) 153- #define LDBL1008 (LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63 * LDBL63) 154- #define LDBL_MAX (LDBL1008 * 65535.0L + LDBL945 * (long double) 9223372036821221375ULL + LDBL882 * (long double) 4611686018427387904ULL) 155- which is represented as { 0x7FEFFFFF, 0xFFFFFFFF, 0x7C8FFFFF, 0xF8000000 }. 156- So, define it like this through a reference to an external variable 157+/* LDBL_MAX is 2**1024 - 2**918, represented as: { 0x7FEFFFFF, 0xFFFFFFFF, 158+ 0x7C9FFFFF, 0xFFFFFFFF }. 159+ 160+ Do not write it as a constant expression, as GCC would likely treat 161+ that as infinity due to the vagaries of this platform's funky arithmetic. 162+ Instead, define it through a reference to an external variable. 163+ Like the following, but using a union to avoid type mismatches: 164 165- const double LDBL_MAX[2] = { DBL_MAX, DBL_MAX / (double)134217728UL / (double)134217728UL }; 166+ const double LDBL_MAX[2] = { DBL_MAX, DBL_MAX / 0x1p53 }; 167 extern const long double LDBL_MAX; 168 169- or through a pointer cast 170+ The following alternative would not work as well when GCC is optimizing: 171+ 172+ #define LDBL_MAX (*(long double const *) (double[]) 173+ { DBL_MAX, DBL_MAX / 0x1p53 }) 174 175- #define LDBL_MAX \ 176- (*(const long double *) (double[]) { DBL_MAX, DBL_MAX / (double)134217728UL / (double)134217728UL }) 177+ The following alternative would require GCC 6 or later: 178 179- Unfortunately, this is not a constant expression, and the latter expression 180- does not work well when GCC is optimizing.. */ 181+ #define LDBL_MAX __builtin_pack_longdouble (DBL_MAX, DBL_MAX / 0x1p53) 182+ 183+ Unfortunately none of the alternatives are constant expressions. */ 184 # if !GNULIB_defined_long_double_union 185 union gl_long_double_union 186 { 187@@ -161,6 +155,8 @@ 188 # endif 189 extern const union gl_long_double_union gl_LDBL_MAX; 190 # define LDBL_MAX (gl_LDBL_MAX.ld) 191+# undef LDBL_NORM_MAX 192+# define LDBL_NORM_MAX LDBL_MAX 193 #endif 194 195 /* On IRIX 6.5, with cc, the value of LDBL_MANT_DIG is wrong. 196@@ -181,6 +177,21 @@ 197 # endif 198 #endif 199 200+/* On PowerPC platforms, 'long double' has a double-double representation. 201+ Up to ISO C 17, this was outside the scope of ISO C because it can represent 202+ numbers with mantissas of the form 1.<52 bits><many zeroes><52 bits>, such as 203+ 1.0L + 4.94065645841246544176568792868221e-324L = 1 + 2^-1074; see 204+ ISO C 17 § 5.2.4.2.2.(3). 205+ In ISO C 23, wording has been included that makes this 'long double' 206+ representation compliant; see ISO C 23 § 5.2.5.3.3.(8)-(9). In this setting, 207+ numbers with mantissas of the form 1.<52 bits><many zeroes><52 bits> are 208+ called "unnormalized". And since LDBL_EPSILON must be normalized (per 209+ ISO C 23 § 5.2.5.3.3.(33)), it must be 2^-105. */ 210+#if defined __powerpc__ && LDBL_MANT_DIG == 106 211+# undef LDBL_EPSILON 212+# define LDBL_EPSILON 2.46519032881566189191165176650870696773e-32L /* 2^-105 */ 213+#endif 214+ 215 /* ============================ ISO C11 support ============================ */ 216 217 /* 'float' properties */ 218@@ -309,7 +320,11 @@ 219 # endif 220 #endif 221 #ifndef LDBL_NORM_MAX 222-# define LDBL_NORM_MAX LDBL_MAX 223+# ifdef __LDBL_NORM_MAX__ 224+# define LDBL_NORM_MAX __LDBL_NORM_MAX__ 225+# else 226+# define LDBL_NORM_MAX LDBL_MAX 227+# endif 228 #endif 229 #ifndef LDBL_SNAN 230 /* For sh, beware of <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111814>. */