changeset 16738:25dda52366fd

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.
author Bruno Haible <bruno@clisp.org>
date Sun, 01 Apr 2012 14:41:57 +0200
parents 6828b991e3b9
children 72d20d33396b
files ChangeLog doc/posix-functions/log10l.texi lib/log10l.c lib/math.in.h m4/log10l.m4 m4/math_h.m4 modules/log10l modules/math
diffstat 8 files changed, 121 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+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.
--- a/doc/posix-functions/log10l.texi
+++ b/doc/posix-functions/log10l.texi
@@ -10,10 +10,19 @@
 @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 only defined as a macro with arguments on some platforms:
+MSVC 9.
 @item
-This function is not declared on some platforms:
+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:
--- a/lib/log10l.c
+++ b/lib/log10l.c
@@ -27,6 +27,19 @@
   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) */
--- a/lib/math.in.h
+++ b/lib/math.in.h
@@ -1235,11 +1235,20 @@
 #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
+_GL_CXXALIAS_SYS (log10l, long double, (long double x));
 # endif
-_GL_CXXALIAS_SYS (log10l, long double, (long double x));
 _GL_CXXALIASWARN (log10l);
 #elif defined GNULIB_POSIXCHECK
 # undef log10l
--- a/m4/log10l.m4
+++ b/m4/log10l.m4
@@ -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 @@
   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
+        ])
+    ])
+])
--- a/m4/math_h.m4
+++ b/m4/math_h.m4
@@ -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 @@
   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])
--- a/modules/log10l
+++ b/modules/log10l
@@ -8,12 +8,12 @@
 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])
--- a/modules/math
+++ b/modules/math
@@ -247,6 +247,7 @@
 	      -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' \