]> Savannah Git Hosting - gnulib.git/commitdiff
expm1l: Work around inaccurate implementation on NetBSD.
authorBruno Haible <bruno@clisp.org>
Sun, 20 Jan 2019 21:28:37 +0000 (22:28 +0100)
committerBruno Haible <bruno@clisp.org>
Sun, 20 Jan 2019 21:28:37 +0000 (22:28 +0100)
* lib/math.in.h (expm1l): Test also REPLACE_EXPM1L.
* m4/expm1l.m4 (gl_FUNC_EXPM1L): Add test for a certain accuracy. Set
REPLACE_EXPM1L.
* m4/math_h.m4 (gl_MATH_H_DEFAULTS): Initialize REPLACE_EXPM1L.
* modules/math (Makefile.in): Substitute REPLACE_EXPM1L.
* modules/expm1l (Depends-on, configure.ac): Test REPLACE_EXPM1L.
* doc/posix-functions/expm1l.texi: Mention the NetBSD bug.

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

index 80f00e29e9b4039517aa60317c99806ded2234d8..07f3cc4e887a71cba5be9952e7bc6ce4211f1713 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2019-01-20  Bruno Haible  <bruno@clisp.org>
+
+       expm1l: Work around inaccurate implementation on NetBSD.
+       * lib/math.in.h (expm1l): Test also REPLACE_EXPM1L.
+       * m4/expm1l.m4 (gl_FUNC_EXPM1L): Add test for a certain accuracy. Set
+       REPLACE_EXPM1L.
+       * m4/math_h.m4 (gl_MATH_H_DEFAULTS): Initialize REPLACE_EXPM1L.
+       * modules/math (Makefile.in): Substitute REPLACE_EXPM1L.
+       * modules/expm1l (Depends-on, configure.ac): Test REPLACE_EXPM1L.
+       * doc/posix-functions/expm1l.texi: Mention the NetBSD bug.
+
 2019-01-20  Bruno Haible  <bruno@clisp.org>
 
        expl: Work around inaccurate implementation on NetBSD.
index 3ccf9b1e5768029c36af6cd258b2954afe22c1d2..75534f299a1a331dc575b8b1a38b4634246f7cbf 100644 (file)
@@ -14,6 +14,10 @@ FreeBSD 6.0, NetBSD 5.0, OpenBSD 3.8, Minix 3.1.8, AIX 5.1, HP-UX 11, older IRIX
 @item
 This function is not declared on some platforms:
 IRIX 6.5.
+@item
+This function produces results which are accurate to only 16 digits on some
+platforms:
+NetBSD 8.0.
 @end itemize
 
 Portability problems not fixed by Gnulib:
index c5f9b466b15dd2e2f920b20a28b018dea4aa2ac9..270caaf4c8ceea5ecc152392919274ee379dd314 100644 (file)
@@ -760,11 +760,20 @@ _GL_WARN_ON_USE (expm1, "expm1 is unportable - "
 #endif
 
 #if @GNULIB_EXPM1L@
-# if !@HAVE_DECL_EXPM1L@
-#  undef expm1l
+# if @REPLACE_EXPM1L@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef expm1l
+#   define expm1l rpl_expm1l
+#  endif
+_GL_FUNCDECL_RPL (expm1l, long double, (long double x));
+_GL_CXXALIAS_RPL (expm1l, long double, (long double x));
+# else
+#  if !@HAVE_DECL_EXPM1L@
+#   undef expm1l
 _GL_FUNCDECL_SYS (expm1l, long double, (long double x));
-# endif
+#  endif
 _GL_CXXALIAS_SYS (expm1l, long double, (long double x));
+# endif
 _GL_CXXALIASWARN (expm1l);
 #elif defined GNULIB_POSIXCHECK
 # undef expm1l
index d0745502ac1b795a7853b92f46afead5484a7d4a..d2307f295aa79d1d8ab5b8d4f86e60264f848a1a 100644 (file)
@@ -1,4 +1,4 @@
-# expm1l.m4 serial 2
+# expm1l.m4 serial 3
 dnl Copyright (C) 2010-2019 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -69,9 +69,101 @@ AC_DEFUN([gl_FUNC_EXPM1L],
     dnl Also check whether it's declared.
     dnl IRIX 6.5 has expm1l() in libm but doesn't declare it in <math.h>.
     AC_CHECK_DECL([expm1l], , [HAVE_DECL_EXPM1L=0], [[#include <math.h>]])
+    if test $REPLACE_EXPM1L = 0; then
+      AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
+      AC_CACHE_CHECK([whether expm1l works],
+        [gl_cv_func_expm1l_works],
+        [
+          save_LIBS="$LIBS"
+          LIBS="$LIBS $EXPM1L_LIBM"
+          AC_RUN_IFELSE(
+            [AC_LANG_SOURCE([[
+#ifndef __NO_MATH_INLINES
+# define __NO_MATH_INLINES 1 /* for glibc */
+#endif
+#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_MANT_DIG
+# define LDBL_MANT_DIG   64
+# undef LDBL_MIN_EXP
+# define LDBL_MIN_EXP    (-16381)
+# undef LDBL_MAX_EXP
+# define LDBL_MAX_EXP    16384
+#endif
+#if defined __i386__ && (defined __FreeBSD__ || defined __DragonFly__)
+# undef LDBL_MANT_DIG
+# define LDBL_MANT_DIG   64
+# undef LDBL_MIN_EXP
+# define LDBL_MIN_EXP    (-16381)
+# undef LDBL_MAX_EXP
+# define LDBL_MAX_EXP    16384
+#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)
+# undef LDBL_MANT_DIG
+# define LDBL_MANT_DIG 106
+# if defined __GNUC__
+#  undef LDBL_MIN_EXP
+#  define LDBL_MIN_EXP DBL_MIN_EXP
+# endif
+#endif
+#undef expm1l
+extern
+#ifdef __cplusplus
+"C"
+#endif
+long double expm1l (long double);
+static long double dummy (long double x) { return 0; }
+int main (int argc, char *argv[])
+{
+  long double (* volatile my_expm1l) (long double) = argc ? expm1l : dummy;
+  int result = 0;
+  /* This test fails on NetBSD 8.0.  */
+  {
+    const long double TWO_LDBL_MANT_DIG = /* 2^LDBL_MANT_DIG */
+      (long double) (1U << ((LDBL_MANT_DIG - 1) / 5))
+      * (long double) (1U << ((LDBL_MANT_DIG - 1 + 1) / 5))
+      * (long double) (1U << ((LDBL_MANT_DIG - 1 + 2) / 5))
+      * (long double) (1U << ((LDBL_MANT_DIG - 1 + 3) / 5))
+      * (long double) (1U << ((LDBL_MANT_DIG - 1 + 4) / 5));
+    long double x = 11.358L;
+    long double y = my_expm1l (x);
+    long double z = my_expm1l (- x);
+    long double err = (y + (1.0L + y) * z) * TWO_LDBL_MANT_DIG;
+    if (!(err >= -100.0L && err <= 100.0L))
+      result |= 1;
+  }
+  return result;
+}
+            ]])],
+            [gl_cv_func_expm1l_works=yes],
+            [gl_cv_func_expm1l_works=no],
+            [case "$host_os" in
+                              # Guess yes on glibc systems.
+               *-gnu* | gnu*) gl_cv_func_expm1l_works="guessing yes" ;;
+                              # Guess yes on native Windows.
+               mingw*)        gl_cv_func_expm1l_works="guessing yes" ;;
+                              # If we don't know, assume the worst.
+               *)             gl_cv_func_expm1l_works="guessing no" ;;
+             esac
+            ])
+          LIBS="$save_LIBS"
+        ])
+      case "$gl_cv_func_expm1l_works" in
+        *yes) ;;
+        *) REPLACE_EXPM1L=1 ;;
+      esac
+    fi
   else
     HAVE_EXPM1L=0
     HAVE_DECL_EXPM1L=0
+  fi
+  if test $HAVE_EXPM1L = 0 || test $REPLACE_EXPM1L = 1; then
     dnl Find libraries needed to link lib/expm1l.c.
     if test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1; then
       AC_REQUIRE([gl_FUNC_EXPM1])
index 2eec8c42c899406e66ce425cf04e76f20f02c8e7..bbbe5d46b0e75a9d5d4f4edaf7bb062fc57a0180 100644 (file)
@@ -1,4 +1,4 @@
-# math_h.m4 serial 117
+# math_h.m4 serial 118
 dnl Copyright (C) 2007-2019 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -271,6 +271,7 @@ AC_DEFUN([gl_MATH_H_DEFAULTS],
   REPLACE_EXPL=0;              AC_SUBST([REPLACE_EXPL])
   REPLACE_EXPM1=0;             AC_SUBST([REPLACE_EXPM1])
   REPLACE_EXPM1F=0;            AC_SUBST([REPLACE_EXPM1F])
+  REPLACE_EXPM1L=0;            AC_SUBST([REPLACE_EXPM1L])
   REPLACE_EXP2=0;              AC_SUBST([REPLACE_EXP2])
   REPLACE_EXP2L=0;             AC_SUBST([REPLACE_EXP2L])
   REPLACE_FABSL=0;             AC_SUBST([REPLACE_FABSL])
index 1f23a0daa05d39dd6e30200515ecf6df53ee990f..f7137e2e41204e2a7d6d9760148fb945ce3777bf 100644 (file)
@@ -8,16 +8,16 @@ m4/expm1l.m4
 Depends-on:
 math
 extensions
-expm1           [test $HAVE_EXPM1L = 0 && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1]
-float           [test $HAVE_EXPM1L = 0 && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 0]
-isnanl          [test $HAVE_EXPM1L = 0 && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 0]
-expl            [test $HAVE_EXPM1L = 0 && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 0]
-roundl          [test $HAVE_EXPM1L = 0 && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 0]
-ldexpl          [test $HAVE_EXPM1L = 0 && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 0]
+expm1           [{ test $HAVE_EXPM1L = 0 || test $REPLACE_EXPM1L = 1; } && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1]
+float           [{ test $HAVE_EXPM1L = 0 || test $REPLACE_EXPM1L = 1; } && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 0]
+isnanl          [{ test $HAVE_EXPM1L = 0 || test $REPLACE_EXPM1L = 1; } && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 0]
+expl            [{ test $HAVE_EXPM1L = 0 || test $REPLACE_EXPM1L = 1; } && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 0]
+roundl          [{ test $HAVE_EXPM1L = 0 || test $REPLACE_EXPM1L = 1; } && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 0]
+ldexpl          [{ test $HAVE_EXPM1L = 0 || test $REPLACE_EXPM1L = 1; } && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 0]
 
 configure.ac:
 gl_FUNC_EXPM1L
-if test $HAVE_EXPM1L = 0; then
+if test $HAVE_EXPM1L = 0 || test $REPLACE_EXPM1L = 1; then
   AC_LIBOBJ([expm1l])
 fi
 gl_MATH_MODULE_INDICATOR([expm1l])
index 77197e51b7b74817f5f90952f67d6e40a9a1ce94..1f23a1787651a43b978f27e080bf43d3064fd779 100644 (file)
@@ -240,6 +240,7 @@ math.h: math.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(
              -e 's|@''REPLACE_EXPL''@|$(REPLACE_EXPL)|g' \
              -e 's|@''REPLACE_EXPM1''@|$(REPLACE_EXPM1)|g' \
              -e 's|@''REPLACE_EXPM1F''@|$(REPLACE_EXPM1F)|g' \
+             -e 's|@''REPLACE_EXPM1L''@|$(REPLACE_EXPM1L)|g' \
              -e 's|@''REPLACE_EXP2''@|$(REPLACE_EXP2)|g' \
              -e 's|@''REPLACE_EXP2L''@|$(REPLACE_EXP2L)|g' \
              -e 's|@''REPLACE_FABSL''@|$(REPLACE_FABSL)|g' \