]> Savannah Git Hosting - gnulib.git/commitdiff
isfinite: Work around a bug with 'long double' in glibc 2.5/ia64.
authorBruno Haible <bruno@clisp.org>
Sun, 8 Oct 2023 07:59:03 +0000 (09:59 +0200)
committerBruno Haible <bruno@clisp.org>
Sun, 5 Nov 2023 19:14:01 +0000 (20:14 +0100)
* m4/isfinite.m4 (gl_ISFINITEL_WORKS): Require
gl_LONG_DOUBLE_EXPONENT_LOCATION. Test also another NaN value.
* modules/isfinite (Files): Add m4/exponentl.m4.
* doc/posix-functions/isfinite.texi: Mention also a 'long double'
problem on ia64.

ChangeLog
doc/posix-functions/isfinite.texi
m4/isfinite.m4
modules/isfinite

index 1112ba613ddd103f59dadccee434ddf281e0ca18..617ece86cbcf4449aec2c704b3d6dd725f89fbf7 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2023-10-08  Bruno Haible  <bruno@clisp.org>
+
+       isfinite: Work around a bug with 'long double' in glibc 2.5/ia64.
+       * m4/isfinite.m4 (gl_ISFINITEL_WORKS): Require
+       gl_LONG_DOUBLE_EXPONENT_LOCATION. Test also another NaN value.
+       * modules/isfinite (Files): Add m4/exponentl.m4.
+       * doc/posix-functions/isfinite.texi: Mention also a 'long double'
+       problem on ia64.
+
 2023-10-02  Bruno Haible  <bruno@clisp.org>
 
        localename, gettext: Avoid crash on macOS 14.
index d6ea43f8188a86a41d75aa5a27713e9bb675744e..8278c9449aba1a2a9f6d60fe39ea1737fac89361 100644 (file)
@@ -12,9 +12,9 @@ Portability problems fixed by Gnulib:
 This macro is missing on some platforms:
 macOS 11.1, OpenBSD 6.7, AIX 5.1, IRIX 6.5, Solaris 11.4.
 @item
-This macro incorrectly yields true for some @samp{double} arguments, on some
-platforms:
-Linux/ia64 (signalling NaNs).
+This macro incorrectly yields true for some @samp{double} and for some
+@samp{long double} arguments, on some platforms:
+Linux/ia64 (NaNs).
 @end itemize
 
 Portability problems not fixed by Gnulib:
index 8f18ae8d6286c142c55652b4acc29a6a2a052d95..f70181e77890109302750b622bfb431a4e2be224 100644 (file)
@@ -1,4 +1,4 @@
-# isfinite.m4 serial 17
+# isfinite.m4 serial 17.1
 dnl Copyright (C) 2007-2023 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -46,6 +46,7 @@ AC_DEFUN([gl_ISFINITEL_WORKS],
 [
   AC_REQUIRE([AC_PROG_CC])
   AC_REQUIRE([gl_BIGENDIAN])
+  AC_REQUIRE([gl_LONG_DOUBLE_EXPONENT_LOCATION])
   AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE])
   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
   AC_CACHE_CHECK([whether isfinite(long double) works], [gl_cv_func_isfinitel_works],
@@ -87,6 +88,31 @@ int main ()
       m.word[i] |= 1;
     if (isfinite (m.value))
       result |= 1;
+
+#if defined LDBL_EXPBIT0_WORD && defined LDBL_EXPBIT0_BIT
+    /* Another NaN, more precisely crafted.  */
+    m.value = NaNl ();
+    #if defined __powerpc__ && LDBL_MANT_DIG == 106
+      /* This is PowerPC "double double", a pair of two doubles.  Inf and NaN are
+         represented as the corresponding 64-bit IEEE values in the first double;
+         the second is ignored.  Manipulate only the first double.  */
+      #define HNWORDS \
+        ((sizeof (double) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
+    #else
+      #define HNWORDS NWORDS
+    #endif
+    #if LDBL_EXPBIT0_BIT > 0
+      m.word[LDBL_EXPBIT0_WORD] ^= (unsigned int) 1 << (LDBL_EXPBIT0_BIT - 1);
+    #else
+      m.word[LDBL_EXPBIT0_WORD + (LDBL_EXPBIT0_WORD < HNWORDS / 2 ? 1 : - 1)]
+        ^= (unsigned int) 1 << (sizeof (unsigned int) * CHAR_BIT - 1);
+    #endif
+    m.word[LDBL_EXPBIT0_WORD + (LDBL_EXPBIT0_WORD < HNWORDS / 2 ? 1 : - 1)]
+      |= (unsigned int) 1 << LDBL_EXPBIT0_BIT;
+    #undef HNWORDS
+    if (isfinite (m.value))
+      result |= 1;
+#endif
   }
 
 #if ((defined __ia64 && LDBL_MANT_DIG == 64) || (defined __x86_64__ || defined __amd64__) || (defined __i386 || defined __i386__ || defined _I386 || defined _M_IX86 || defined _X86_)) && !HAVE_SAME_LONG_DOUBLE_AS_DOUBLE
index 9933109cb0bc5bccfde4ab92889fd2b2791d00a3..0e801457bd785aa0de2f382103e0ce68b2e4b72c 100644 (file)
@@ -5,6 +5,7 @@ Files:
 lib/isfinite.c
 m4/isfinite.m4
 m4/check-math-lib.m4
+m4/exponentl.m4
 
 Depends-on:
 math