]> Savannah Git Hosting - gnulib.git/commitdiff
ilogbl: Ensure replacement on Haiku.
authorBruno Haible <bruno@clisp.org>
Sun, 29 Oct 2017 11:57:35 +0000 (12:57 +0100)
committerBruno Haible <bruno@clisp.org>
Sun, 29 Oct 2017 20:27:51 +0000 (21:27 +0100)
* 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.

ChangeLog
doc/posix-functions/ilogbl.texi
lib/math.in.h
m4/ilogbl.m4
m4/math_h.m4
modules/ilogbl
modules/math

index 53745fc91a79e3aebd5915a22bd8a0893b4a7b0d..9bfd408f39999567f5a7228078b9245263f694e5 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -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.
index 9580a5cfbd133f939e61657e7135b6210116e6c3..f1ca24bbf73304b692d1f97f6fbb021b2ab1481a 100644 (file)
@@ -11,6 +11,9 @@ Portability problems fixed by Gnulib:
 @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:
index 09f822aa5e37146b870de3017a5e058b784ef6a9..5681597884046933352b030df8da34ebe07bf3cf 100644 (file)
@@ -1223,10 +1223,19 @@ _GL_WARN_ON_USE (ilogb, "ilogb is unportable - "
 #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
+#  endif
 _GL_CXXALIAS_SYS (ilogbl, int, (long double x));
+# endif
 _GL_CXXALIASWARN (ilogbl);
 #elif defined GNULIB_POSIXCHECK
 # undef ilogbl
index 44556a9d1c86a1bed037a3ae06b7c948532359fa..60cb14118e1cba3af5b8b0a2b3c6c40c50d0c95a 100644 (file)
@@ -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 @@ AC_DEFUN([gl_FUNC_ILOGBL],
   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 @@ AC_DEFUN([gl_FUNC_ILOGBL],
   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
+        ])
+    ])
+])
index 6db72ca63515c19029e9f76952511b923c43b5c9..b9a432eea9ad18a9cfcef4e79a4aa864b7a719a5 100644 (file)
@@ -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 @@ AC_DEFUN([gl_MATH_H_DEFAULTS],
   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])
index d31ad263a70152c47d4d69a707ac817e96e0071c..3d321aaeb51bd18156d4d28428bdf9bb24318607 100644 (file)
@@ -10,14 +10,14 @@ m4/mathfunc.m4
 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])
index 2f553baf2d67bff8529970e15b3e8a8e08349c86..d53951815c2cec86a8341604d75ef241e958e8b4 100644 (file)
@@ -260,6 +260,7 @@ math.h: math.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(
              -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' \