log10l: Work around AIX 5.1, IRIX 6.5, OSF/1 5.1 bug.
authorBruno Haible <bruno@clisp.org>
Sun, 1 Apr 2012 12:41:57 +0000 (14:41 +0200)
committerBruno Haible <bruno@clisp.org>
Sun, 1 Apr 2012 14:37:09 +0000 (16:37 +0200)
* lib/math.in.h (log10l): Override if REPLACE_LOG10L is 1.
* lib/log10l.c (log10l): If log10l exists, use it and provide just the
workaround.
* m4/log10l.m4 (gl_FUNC_LOG10L_WORKS): New macro.
(gl_FUNC_LOG10L): Invoke it. Set REPLACE_LOG10L.
* m4/math_h.m4 (gl_MATH_H_DEFAULTS): Initialize REPLACE_LOG10L.
* modules/math (Makefile.am): Substitute REPLACE_LOG10L.
* modules/log10l (configure.ac): Consider REPLACE_LOG10L.
(Depends-on): Update conditions.
* doc/posix-functions/log10l.texi: Mention the MSVC9, AIX 5.1,
IRIX 6.5, OSF/1 5.1 problems.

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

index 06eb7fb..d5d6386 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,20 @@
 2012-04-01  Bruno Haible  <bruno@clisp.org>
 
+       log10l: Work around AIX 5.1, IRIX 6.5, OSF/1 5.1 bug.
+       * lib/math.in.h (log10l): Override if REPLACE_LOG10L is 1.
+       * lib/log10l.c (log10l): If log10l exists, use it and provide just the
+       workaround.
+       * m4/log10l.m4 (gl_FUNC_LOG10L_WORKS): New macro.
+       (gl_FUNC_LOG10L): Invoke it. Set REPLACE_LOG10L.
+       * m4/math_h.m4 (gl_MATH_H_DEFAULTS): Initialize REPLACE_LOG10L.
+       * modules/math (Makefile.am): Substitute REPLACE_LOG10L.
+       * modules/log10l (configure.ac): Consider REPLACE_LOG10L.
+       (Depends-on): Update conditions.
+       * doc/posix-functions/log10l.texi: Mention the MSVC9, AIX 5.1,
+       IRIX 6.5, OSF/1 5.1 problems.
+
+2012-04-01  Bruno Haible  <bruno@clisp.org>
+
        log10f: Work around OSF/1 5.1 bug.
        * lib/math.in.h (log10f): Override if REPLACE_LOG10F is 1.
        * lib/log10f.c (log10f): If logf exists, use it and provide just the
index 1f29c1b..eb8eec8 100644 (file)
@@ -10,10 +10,19 @@ Portability problems fixed by Gnulib:
 @itemize
 @item
 This function is missing on some platforms:
-FreeBSD 6.0, NetBSD 5.0, OpenBSD 3.8, Minix 3.1.8, HP-UX 11, IRIX 6.5, Solaris 9, Cygwin, Interix 3.5, BeOS.
+FreeBSD 6.0, NetBSD 5.0, OpenBSD 3.8, Minix 3.1.8, HP-UX 11, older IRIX 6.5, Solaris 9, Cygwin, Interix 3.5, BeOS.
 @item
-This function is not declared on some platforms:
+This function is only defined as a macro with arguments on some platforms:
+MSVC 9.
+@item
+This function is not declared and does not work on some platforms:
 AIX 5.1.
+@item
+This function returns a wrong value for a minus zero argument on some platforms:
+OSF/1 5.1.
+@item
+This function returns an unnormalized negative infinity for a minus zero argument on some platforms:
+IRIX 6.5.
 @end itemize
 
 Portability problems not fixed by Gnulib:
index ecaacb2..f108538 100644 (file)
@@ -27,6 +27,19 @@ log10l (long double x)
   return log10 (x);
 }
 
+#elif HAVE_LOG10L
+
+long double
+log10l (long double x)
+# undef log10l
+{
+  /* Work around the OSF/1 5.1 bug.  */
+  if (x == 0.0L)
+    /* Return -Infinity.  */
+    return -1.0L / 0.0L;
+  return log10l (x);
+}
+
 #else
 
 /* 1 / log(10) */
index 335238d..f5c5f03 100644 (file)
@@ -1235,11 +1235,20 @@ _GL_WARN_ON_USE (log10, "log10 has portability problems - "
 #endif
 
 #if @GNULIB_LOG10L@
-# if !@HAVE_LOG10L@ || !@HAVE_DECL_LOG10L@
-#  undef log10l
+# if @REPLACE_LOG10L@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef log10l
+#   define log10l rpl_log10l
+#  endif
+_GL_FUNCDECL_RPL (log10l, long double, (long double x));
+_GL_CXXALIAS_RPL (log10l, long double, (long double x));
+# else
+#  if !@HAVE_LOG10L@ || !@HAVE_DECL_LOG10L@
+#   undef log10l
 _GL_FUNCDECL_SYS (log10l, long double, (long double x));
-# endif
+#  endif
 _GL_CXXALIAS_SYS (log10l, long double, (long double x));
+# endif
 _GL_CXXALIASWARN (log10l);
 #elif defined GNULIB_POSIXCHECK
 # undef log10l
index c124f89..df614b1 100644 (file)
@@ -1,4 +1,4 @@
-# log10l.m4 serial 2
+# log10l.m4 serial 3
 dnl Copyright (C) 2011-2012 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -24,14 +24,75 @@ AC_DEFUN([gl_FUNC_LOG10L],
   LIBS="$save_LIBS"
   if test $ac_cv_func_log10l = yes; then
     LOG10L_LIBM="$LOG10_LIBM"
+
+    save_LIBS="$LIBS"
+    LIBS="$LIBS $LOG10L_LIBM"
+    gl_FUNC_LOG10L_WORKS
+    LIBS="$save_LIBS"
+    case "$gl_cv_func_log10l_works" in
+      *yes) ;;
+      *) REPLACE_LOG10L=1 ;;
+    esac
   else
     HAVE_LOG10L=0
+  fi
+  if test $HAVE_LOG10L = 0 || test $REPLACE_LOG10L = 1; then
     if test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1; then
       LOG10L_LIBM="$LOG10_LIBM"
     else
-      AC_REQUIRE([gl_FUNC_LOGL])
-      LOG10L_LIBM="$LOGL_LIBM"
+      if test $HAVE_LOG10L = 0; then
+        AC_REQUIRE([gl_FUNC_LOGL])
+        LOG10L_LIBM="$LOGL_LIBM"
+      fi
     fi
   fi
   AC_SUBST([LOG10L_LIBM])
 ])
+
+dnl Test whether log10l() works.
+dnl On OSF/1 5.1, log10l(-0.0L) is NaN.
+dnl On IRIX 6.5, log10l(-0.0L) is an unnormalized negative infinity
+dnl 0xFFF00000000000007FF0000000000000, should be
+dnl 0xFFF00000000000000000000000000000.
+dnl On AIX 5.1, log10l(-0.0L) is finite if it's not the first log10l call
+dnl in the program.
+AC_DEFUN([gl_FUNC_LOG10L_WORKS],
+[
+  AC_REQUIRE([AC_PROG_CC])
+  AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
+  AC_CACHE_CHECK([whether log10l works], [gl_cv_func_log10l_works],
+    [
+      AC_RUN_IFELSE(
+        [AC_LANG_SOURCE([[
+#include <math.h>
+#ifndef log10l /* for AIX */
+extern
+#ifdef __cplusplus
+"C"
+#endif
+long double log10l (long double);
+#endif
+volatile long double x;
+long double y;
+int main ()
+{
+  /* Dummy call, to trigger the AIX 5.1 bug.  */
+  x = 0.6L;
+  y = log10l (x);
+  /* This test fails on AIX 5.1, IRIX 6.5, OSF/1 5.1.  */
+  x = -0.0L;
+  y = log10l (x);
+  if (!(y + y == y))
+    return 1;
+  return 0;
+}
+]])],
+        [gl_cv_func_log10l_works=yes],
+        [gl_cv_func_log10l_works=no],
+        [case "$host_os" in
+           aix* | irix* | osf*) gl_cv_func_log10l_works="guessing no";;
+           *)                   gl_cv_func_log10l_works="guessing yes";;
+         esac
+        ])
+    ])
+])
index 5bfa28c..a24d352 100644 (file)
@@ -1,4 +1,4 @@
-# math_h.m4 serial 106
+# math_h.m4 serial 107
 dnl Copyright (C) 2007-2012 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -280,6 +280,7 @@ AC_DEFUN([gl_MATH_H_DEFAULTS],
   REPLACE_LOGL=0;              AC_SUBST([REPLACE_LOGL])
   REPLACE_LOG10=0;             AC_SUBST([REPLACE_LOG10])
   REPLACE_LOG10F=0;            AC_SUBST([REPLACE_LOG10F])
+  REPLACE_LOG10L=0;            AC_SUBST([REPLACE_LOG10L])
   REPLACE_LOG1P=0;             AC_SUBST([REPLACE_LOG1P])
   REPLACE_LOG1PF=0;            AC_SUBST([REPLACE_LOG1PF])
   REPLACE_LOG1PL=0;            AC_SUBST([REPLACE_LOG1PL])
index 16b49cd..cad6bbe 100644 (file)
@@ -8,12 +8,12 @@ m4/log10l.m4
 Depends-on:
 math
 extensions
-log10           [test $HAVE_LOG10L = 0 && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1]
-logl            [test $HAVE_LOG10L = 0 && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 0]
+log10           [{ test $HAVE_LOG10L = 0 || test $REPLACE_LOG10L = 1; } && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1]
+logl            [{ test $HAVE_LOG10L = 0 || test $REPLACE_LOG10L = 1; } && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 0]
 
 configure.ac:
 gl_FUNC_LOG10L
-if test $HAVE_LOG10L = 0; then
+if test $HAVE_LOG10L = 0 || test $REPLACE_LOG10L = 1; then
   AC_LIBOBJ([log10l])
 fi
 gl_MATH_MODULE_INDICATOR([log10l])
index cb81a7d..68fe958 100644 (file)
@@ -247,6 +247,7 @@ math.h: math.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(
              -e 's|@''REPLACE_LOGL''@|$(REPLACE_LOGL)|g' \
              -e 's|@''REPLACE_LOG10''@|$(REPLACE_LOG10)|g' \
              -e 's|@''REPLACE_LOG10F''@|$(REPLACE_LOG10F)|g' \
+             -e 's|@''REPLACE_LOG10L''@|$(REPLACE_LOG10L)|g' \
              -e 's|@''REPLACE_LOG1P''@|$(REPLACE_LOG1P)|g' \
              -e 's|@''REPLACE_LOG1PF''@|$(REPLACE_LOG1PF)|g' \
              -e 's|@''REPLACE_LOG1PL''@|$(REPLACE_LOG1PL)|g' \