On Cygwin 3.4.6, I see this test failure:

FAIL: test-ilogbl
=================

../../gltests/test-ilogb.h:68: assertion 'ILOGB (NAN) == FP_ILOGBNAN' failed
FAIL test-ilogbl.exe (exit status: 134)

This patch provides a workaround.


2023-04-18  Bruno Haible  <br...@clisp.org>

        ilogbl: Work around a Cygwin 3.4.6 bug.
        * m4/ilogbl.m4 (gl_FUNC_ILOGBL_WORKS): Also test the value of
        ilogbl(NaN).
        * doc/posix-functions/ilogbl.texi: Mention the new Cygwin bug.

diff --git a/doc/posix-functions/ilogbl.texi b/doc/posix-functions/ilogbl.texi
index a038376f88..dab44c8367 100644
--- a/doc/posix-functions/ilogbl.texi
+++ b/doc/posix-functions/ilogbl.texi
@@ -16,6 +16,10 @@
 @c https://cygwin.com/ml/cygwin/2019-12/msg00074.html
 Cygwin 2.9.
 @item
+This function returns a wrong result for a NaN argument on some platforms:
+@c https://cygwin.com/pipermail/cygwin/2023-April/253511.html
+Cygwin 3.4.6.
+@item
 This function returns a wrong result for denormalized arguments on some 
platforms:
 AIX 7.1 64-bit, Haiku 2017.
 @end itemize
diff --git a/m4/ilogbl.m4 b/m4/ilogbl.m4
index 9081724b66..b25323e95f 100644
--- a/m4/ilogbl.m4
+++ b/m4/ilogbl.m4
@@ -1,4 +1,4 @@
-# ilogbl.m4 serial 5
+# ilogbl.m4 serial 6
 dnl Copyright (C) 2010-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,
@@ -72,6 +72,7 @@ AC_DEFUN([gl_FUNC_ILOGBL]
 
 dnl Test whether ilogbl() works.
 dnl On Cygwin 2.9, ilogbl(0.0L) is wrong.
+dnl On Cygwin 3.4.6, ilogbl(NaN) is wrong.
 dnl On AIX 7.1 in 64-bit mode, ilogbl(2^(LDBL_MIN_EXP-1)) is wrong.
 dnl On Haiku 2017, it returns i-2 instead of i-1 for values between
 dnl ca. 2^-16444 and ca. 2^-16382.
@@ -104,6 +105,17 @@ AC_DEFUN([gl_FUNC_ILOGBL_WORKS]
 #  define LDBL_MIN_EXP DBL_MIN_EXP
 # endif
 #endif
+/* On Irix 6.5, gcc 3.4.3 can't compute compile-time NaN, and needs the
+   runtime type conversion.  */
+#ifdef __sgi
+static long double NaNl ()
+{
+  double zero = 0.0;
+  return zero / zero;
+}
+#else
+# define NaNl() (0.0L / 0.0L)
+#endif
 volatile long double x;
 static int dummy (long double x) { return 0; }
 int main (int argc, char *argv[])
@@ -116,6 +128,12 @@ AC_DEFUN([gl_FUNC_ILOGBL_WORKS]
     if (my_ilogbl (x) != FP_ILOGB0)
       result |= 1;
   }
+  /* This test fails on Cygwin 3.4.6.  */
+  {
+    x = NaNl ();
+    if (my_ilogbl (x) != FP_ILOGBNAN)
+      result |= 2;
+  }
   /* This test fails on AIX 7.1 in 64-bit mode.  */
   {
     int i;
@@ -123,7 +141,7 @@ AC_DEFUN([gl_FUNC_ILOGBL_WORKS]
     for (i = LDBL_MIN_EXP - 1; i < 0; i++)
       x = x * 0.5L;
     if (x > 0.0L && my_ilogbl (x) != LDBL_MIN_EXP - 2)
-      result |= 2;
+      result |= 4;
   }
   /* This test fails on Haiku 2017.  */
   {
@@ -131,7 +149,7 @@ AC_DEFUN([gl_FUNC_ILOGBL_WORKS]
     for (i = 1, x = (long double)1.0; i >= LDBL_MIN_EXP-100 && x > (long 
double)0.0; i--, x *= (long double)0.5)
       if (my_ilogbl (x) != i - 1)
         {
-          result |= 4;
+          result |= 8;
           break;
         }
   }




Reply via email to