changeset 38919:b8611026be0c

ilogbl: Ensure replacement on Haiku. * m4/ilogbl.m4 (gl_FUNC_ILOGBL): Invoke gl_FUNC_ILOGBL_WORKS and set REPLACE_ILOGBL if ilogbl does not work. (gl_FUNC_ILOGBL_WORKS): New macro. * lib/math.in.h (ilogbl): Replace if REPLACE_ILOGBL is 1. * m4/math_h.m4 (gl_MATH_H_DEFAULTS): Initialize REPLACE_ILOGBL. * modules/math (Makefile.am): Substitute REPLACE_ILOGBL. * modules/ilogbl (Depends-on, configure.ac): Consider REPLACE_ILOGBL. * doc/posix-functions/ilogbl.texi: Mention the Haiku problem.
author Bruno Haible <bruno@clisp.org>
date Sun, 29 Oct 2017 12:57:35 +0100
parents 9675e3175444
children 4098349dde39
files ChangeLog doc/posix-functions/ilogbl.texi lib/math.in.h m4/ilogbl.m4 m4/math_h.m4 modules/ilogbl modules/math
diffstat 7 files changed, 108 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Sun Oct 29 11:16:56 2017 +0100
+++ b/ChangeLog	Sun Oct 29 12:57:35 2017 +0100
@@ -1,3 +1,15 @@
+2017-10-29  Bruno Haible  <bruno@clisp.org>
+
+	ilogbl: Ensure replacement on Haiku.
+	* m4/ilogbl.m4 (gl_FUNC_ILOGBL): Invoke gl_FUNC_ILOGBL_WORKS and set
+	REPLACE_ILOGBL if ilogbl does not work.
+	(gl_FUNC_ILOGBL_WORKS): New macro.
+	* lib/math.in.h (ilogbl): Replace if REPLACE_ILOGBL is 1.
+	* m4/math_h.m4 (gl_MATH_H_DEFAULTS): Initialize REPLACE_ILOGBL.
+	* modules/math (Makefile.am): Substitute REPLACE_ILOGBL.
+	* modules/ilogbl (Depends-on, configure.ac): Consider REPLACE_ILOGBL.
+	* doc/posix-functions/ilogbl.texi: Mention the Haiku problem.
+
 2017-10-29  Bruno Haible  <bruno@clisp.org>
 
 	expl: Ensure replacement on Haiku.
--- a/doc/posix-functions/ilogbl.texi	Sun Oct 29 11:16:56 2017 +0100
+++ b/doc/posix-functions/ilogbl.texi	Sun Oct 29 12:57:35 2017 +0100
@@ -11,6 +11,9 @@
 @item
 This function is missing on some platforms:
 FreeBSD 5.2.1, NetBSD 5.0, OpenBSD 3.8, Minix 3.1.8, AIX 5.1, HP-UX 11, IRIX 6.5, Solaris 9, Cygwin, MSVC 9, Interix 3.5, BeOS.
+@item
+This function returns a wrong result for denormalized arguments on some platforms:
+Haiku 2017.
 @end itemize
 
 Portability problems not fixed by Gnulib:
--- a/lib/math.in.h	Sun Oct 29 11:16:56 2017 +0100
+++ b/lib/math.in.h	Sun Oct 29 12:57:35 2017 +0100
@@ -1223,10 +1223,19 @@
 #endif
 
 #if @GNULIB_ILOGBL@
-# if !@HAVE_ILOGBL@
+# if @REPLACE_ILOGBL@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef ilogbl
+#   define ilogbl rpl_ilogbl
+#  endif
+_GL_FUNCDECL_RPL (ilogbl, int, (long double x));
+_GL_CXXALIAS_RPL (ilogbl, int, (long double x));
+# else
+#  if !@HAVE_ILOGBL@
 _GL_FUNCDECL_SYS (ilogbl, int, (long double x));
+#  endif
+_GL_CXXALIAS_SYS (ilogbl, int, (long double x));
 # endif
-_GL_CXXALIAS_SYS (ilogbl, int, (long double x));
 _GL_CXXALIASWARN (ilogbl);
 #elif defined GNULIB_POSIXCHECK
 # undef ilogbl
--- a/m4/ilogbl.m4	Sun Oct 29 11:16:56 2017 +0100
+++ b/m4/ilogbl.m4	Sun Oct 29 12:57:35 2017 +0100
@@ -1,4 +1,4 @@
-# ilogbl.m4 serial 1
+# ilogbl.m4 serial 2
 dnl Copyright (C) 2010-2017 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -36,8 +36,18 @@
   LIBS="$save_LIBS"
   if test $gl_cv_func_ilogbl = yes; then
     ILOGBL_LIBM="$ILOGB_LIBM"
+    save_LIBS="$LIBS"
+    LIBS="$LIBS $ILOGBL_LIBM"
+    gl_FUNC_ILOGBL_WORKS
+    LIBS="$save_LIBS"
+    case "$gl_cv_func_ilogbl_works" in
+      *yes) ;;
+      *) REPLACE_ILOGBL=1 ;;
+    esac
   else
     HAVE_ILOGBL=0
+  fi
+  if test $HAVE_ILOGBL = 0 || test $REPLACE_ILOGBL = 1; then
     dnl Find libraries needed to link lib/ilogbl.c.
     if test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1; then
       ILOGBL_LIBM="$ILOGB_LIBM"
@@ -59,3 +69,66 @@
   fi
   AC_SUBST([ILOGBL_LIBM])
 ])
+
+dnl Test whether ilogbl() works.
+dnl On Haiku 2017, it returns i-2 instead of i-1 for values between
+dnl ca. 2^-16444 and ca. 2^-16382.
+AC_DEFUN([gl_FUNC_ILOGBL_WORKS],
+[
+  AC_REQUIRE([AC_PROG_CC])
+  AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
+  AC_CACHE_CHECK([whether ilogbl works], [gl_cv_func_ilogbl_works],
+    [
+      AC_RUN_IFELSE(
+        [AC_LANG_SOURCE([[
+#include <float.h>
+#include <math.h>
+/* Override the values of <float.h>, like done in float.in.h.  */
+#if defined __i386__ && (defined __BEOS__ || defined __OpenBSD__)
+# undef LDBL_MIN_EXP
+# define LDBL_MIN_EXP    (-16381)
+#endif
+#if defined __i386__ && (defined __FreeBSD__ || defined __DragonFly__)
+# undef LDBL_MIN_EXP
+# define LDBL_MIN_EXP    (-16381)
+#endif
+#if (defined _ARCH_PPC || defined _POWER) && defined _AIX && (LDBL_MANT_DIG == 106) && defined __GNUC__
+# undef LDBL_MIN_EXP
+# define LDBL_MIN_EXP DBL_MIN_EXP
+#endif
+#if defined __sgi && (LDBL_MANT_DIG >= 106)
+# if defined __GNUC__
+#  undef LDBL_MIN_EXP
+#  define LDBL_MIN_EXP DBL_MIN_EXP
+# endif
+#endif
+volatile long double x;
+static int dummy (long double x) { return 0; }
+int main (int argc, char *argv[])
+{
+  int (*my_ilogbl) (long double) = argc ? ilogbl : dummy;
+  int result = 0;
+  /* This test fails on Haiku 2017.  */
+  {
+    int i;
+    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 |= 1;
+          break;
+        }
+  }
+  return result;
+}
+]])],
+        [gl_cv_func_ilogbl_works=yes],
+        [gl_cv_func_ilogbl_works=no],
+        [case "$host_os" in
+           haiku*) gl_cv_func_ilogbl_works="guessing no" ;;
+                   # Guess yes on native Windows.
+           mingw*) gl_cv_func_ilogbl_works="guessing yes" ;;
+           *)      gl_cv_func_ilogbl_works="guessing yes" ;;
+         esac
+        ])
+    ])
+])
--- a/m4/math_h.m4	Sun Oct 29 11:16:56 2017 +0100
+++ b/m4/math_h.m4	Sun Oct 29 12:57:35 2017 +0100
@@ -1,4 +1,4 @@
-# math_h.m4 serial 115
+# math_h.m4 serial 116
 dnl Copyright (C) 2007-2017 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -291,6 +291,7 @@
   REPLACE_HYPOTL=0;            AC_SUBST([REPLACE_HYPOTL])
   REPLACE_ILOGB=0;             AC_SUBST([REPLACE_ILOGB])
   REPLACE_ILOGBF=0;            AC_SUBST([REPLACE_ILOGBF])
+  REPLACE_ILOGBL=0;            AC_SUBST([REPLACE_ILOGBL])
   REPLACE_ISFINITE=0;          AC_SUBST([REPLACE_ISFINITE])
   REPLACE_ISINF=0;             AC_SUBST([REPLACE_ISINF])
   REPLACE_ISNAN=0;             AC_SUBST([REPLACE_ISNAN])
--- a/modules/ilogbl	Sun Oct 29 11:16:56 2017 +0100
+++ b/modules/ilogbl	Sun Oct 29 12:57:35 2017 +0100
@@ -10,14 +10,14 @@
 Depends-on:
 math
 extensions
-ilogb           [test $HAVE_ILOGBL = 0 && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1]
-isfinite        [test $HAVE_ILOGBL = 0 && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 0]
-frexpl          [test $HAVE_ILOGBL = 0 && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 0]
-isnanl          [test $HAVE_ILOGBL = 0 && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 0]
+ilogb           [{ test $HAVE_ILOGBL = 0 || test $REPLACE_ILOGBL = 1; } && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1]
+isfinite        [{ test $HAVE_ILOGBL = 0 || test $REPLACE_ILOGBL = 1; } && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 0]
+frexpl          [{ test $HAVE_ILOGBL = 0 || test $REPLACE_ILOGBL = 1; } && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 0]
+isnanl          [{ test $HAVE_ILOGBL = 0 || test $REPLACE_ILOGBL = 1; } && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 0]
 
 configure.ac:
 gl_FUNC_ILOGBL
-if test $HAVE_ILOGBL = 0; then
+if test $HAVE_ILOGBL = 0 || test $REPLACE_ILOGBL = 1; then
   AC_LIBOBJ([ilogbl])
 fi
 gl_MATH_MODULE_INDICATOR([ilogbl])
--- a/modules/math	Sun Oct 29 11:16:56 2017 +0100
+++ b/modules/math	Sun Oct 29 12:57:35 2017 +0100
@@ -260,6 +260,7 @@
 	      -e 's|@''REPLACE_HYPOTL''@|$(REPLACE_HYPOTL)|g' \
 	      -e 's|@''REPLACE_ILOGB''@|$(REPLACE_ILOGB)|g' \
 	      -e 's|@''REPLACE_ILOGBF''@|$(REPLACE_ILOGBF)|g' \
+	      -e 's|@''REPLACE_ILOGBL''@|$(REPLACE_ILOGBL)|g' \
 	      -e 's|@''REPLACE_ISFINITE''@|$(REPLACE_ISFINITE)|g' \
 	      -e 's|@''REPLACE_ISINF''@|$(REPLACE_ISINF)|g' \
 	      -e 's|@''REPLACE_ISNAN''@|$(REPLACE_ISNAN)|g' \