log1p-ieee: Work around test failure on AIX 7.1 and HP-UX 11.
authorBruno Haible <bruno@clisp.org>
Sun, 11 Mar 2012 00:27:59 +0000 (01:27 +0100)
committerBruno Haible <bruno@clisp.org>
Sun, 11 Mar 2012 01:40:43 +0000 (02:40 +0100)
* m4/log1p-ieee.m4: New file.
* m4/log1p.m4 (gl_FUNC_LOG1P): If gl_FUNC_LOG1P_IEEE is present, test
whether log1p works with a minus zero argument. Replace it if not.
* lib/math.in.h (log1p): Override if REPLACE_LOG1P is 1.
* m4/math_h.m4 (gl_MATH_H_DEFAULTS): Initialize REPLACE_LOG1P.
* modules/math (Makefile.am): Substitute REPLACE_LOG1P.
* modules/log1p (configure.ac): Consider REPLACE_LOG1P.
(Depends-on): Update conditions.
* modules/log1p-ieee (Files): Add m4/log1p-ieee.m4, m4/minus-zero.m4,
m4/signbit.m4.
(configure.ac): Invoke gl_FUNC_LOG1P_IEEE.
* doc/posix-functions/log1p.texi: Mention the log1p-ieee module.

ChangeLog
doc/posix-functions/log1p.texi
lib/math.in.h
m4/log1p-ieee.m4 [new file with mode: 0644]
m4/log1p.m4
m4/math_h.m4
modules/log1p
modules/log1p-ieee
modules/math

index e42a134..874af82 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,19 @@
 2012-03-10  Bruno Haible  <bruno@clisp.org>
 
+       log1p-ieee: Work around test failure on AIX 7.1 and HP-UX 11.
+       * m4/log1p-ieee.m4: New file.
+       * m4/log1p.m4 (gl_FUNC_LOG1P): If gl_FUNC_LOG1P_IEEE is present, test
+       whether log1p works with a minus zero argument. Replace it if not.
+       * lib/math.in.h (log1p): Override if REPLACE_LOG1P is 1.
+       * m4/math_h.m4 (gl_MATH_H_DEFAULTS): Initialize REPLACE_LOG1P.
+       * modules/math (Makefile.am): Substitute REPLACE_LOG1P.
+       * modules/log1p (configure.ac): Consider REPLACE_LOG1P.
+       (Depends-on): Update conditions.
+       * modules/log1p-ieee (Files): Add m4/log1p-ieee.m4, m4/minus-zero.m4,
+       m4/signbit.m4.
+       (configure.ac): Invoke gl_FUNC_LOG1P_IEEE.
+       * doc/posix-functions/log1p.texi: Mention the log1p-ieee module.
+
        Tests for module 'log1pl-ieee'.
        * modules/log1pl-ieee-tests: New file.
        * tests/test-log1pl-ieee.c: New file.
index a63b75b..0e1f3aa 100644 (file)
@@ -4,15 +4,22 @@
 
 POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/log1p.html}
 
-Gnulib module: log1p
+Gnulib module: log1p or log1p-ieee
 
-Portability problems fixed by Gnulib:
+Portability problems fixed by either Gnulib module @code{log1p} or @code{log1p-ieee}:
 @itemize
 @item
 This function is missing on some platforms:
 Minix 3.1.8, MSVC 9.
 @end itemize
 
+Portability problems fixed by Gnulib module @code{log1p-ieee}:
+@itemize
+@item
+This function has problems when the argument is minus zero on some platforms:
+AIX 7.1, HP-UX 11.
+@end itemize
+
 Portability problems not fixed by Gnulib:
 @itemize
 @end itemize
index 9d81590..5128dcc 100644 (file)
@@ -1245,10 +1245,19 @@ _GL_WARN_ON_USE (log1pf, "log1pf is unportable - "
 #endif
 
 #if @GNULIB_LOG1P@
-# if !@HAVE_LOG1P@
+# if @REPLACE_LOG1P@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef log1p
+#   define log1p rpl_log1p
+#  endif
+_GL_FUNCDECL_RPL (log1p, double, (double x));
+_GL_CXXALIAS_RPL (log1p, double, (double x));
+# else
+#  if !@HAVE_LOG1P@
 _GL_FUNCDECL_SYS (log1p, double, (double x));
-# endif
+#  endif
 _GL_CXXALIAS_SYS (log1p, double, (double x));
+# endif
 _GL_CXXALIASWARN (log1p);
 #elif defined GNULIB_POSIXCHECK
 # undef log1p
diff --git a/m4/log1p-ieee.m4 b/m4/log1p-ieee.m4
new file mode 100644 (file)
index 0000000..2391af8
--- /dev/null
@@ -0,0 +1,15 @@
+# log1p-ieee.m4 serial 1
+dnl Copyright (C) 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,
+dnl with or without modifications, as long as this notice is preserved.
+
+dnl This macro is in a separate file (not in remainder.m4 and not inlined in the
+dnl module description), so that gl_FUNC_LOG1P can test whether 'aclocal' has
+dnl found uses of this macro.
+
+AC_DEFUN([gl_FUNC_LOG1P_IEEE],
+[
+  m4_divert_text([INIT_PREPARE], [gl_log1p_required=ieee])
+  AC_REQUIRE([gl_FUNC_LOG1P])
+])
index f692ca0..8d2b15c 100644 (file)
@@ -1,4 +1,4 @@
-# log1p.m4 serial 1
+# log1p.m4 serial 2
 dnl Copyright (C) 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,
@@ -6,6 +6,7 @@ dnl with or without modifications, as long as this notice is preserved.
 
 AC_DEFUN([gl_FUNC_LOG1P],
 [
+  m4_divert_text([DEFAULTS], [gl_log1p_required=plain])
   AC_REQUIRE([gl_MATH_H_DEFAULTS])
 
   dnl Persuade glibc <math.h> to declare log1p().
@@ -19,8 +20,49 @@ AC_DEFUN([gl_FUNC_LOG1P],
   LIBS="$LIBS $LOG1P_LIBM"
   AC_CHECK_FUNCS([log1p])
   LIBS="$save_LIBS"
-  if test $ac_cv_func_log1p = no; then
+  if test $ac_cv_func_log1p = yes; then
+    :
+    m4_ifdef([gl_FUNC_LOG1P_IEEE], [
+      if test $gl_log1p_required = ieee && test $REPLACE_LOG1P = 0; then
+        AC_CACHE_CHECK([whether log1p works according to ISO C 99 with IEC 60559],
+          [gl_cv_func_log1p_ieee],
+          [
+            save_LIBS="$LIBS"
+            LIBS="$LIBS $LOG1P_LIBM"
+            AC_RUN_IFELSE(
+              [AC_LANG_SOURCE([[
+#ifndef __NO_MATH_INLINES
+# define __NO_MATH_INLINES 1 /* for glibc */
+#endif
+#include <math.h>
+]gl_DOUBLE_MINUS_ZERO_CODE[
+]gl_DOUBLE_SIGNBIT_CODE[
+static double dummy (double x) { return 0; }
+int main (int argc, char *argv[])
+{
+  double (*my_log1p) (double) = argc ? log1p : dummy;
+  /* This test fails on AIX, HP-UX 11.  */
+  double y = my_log1p (minus_zerod);
+  if (!(y == 0.0) || (signbitd (minus_zerod) && !signbitd (y)))
+    return 1;
+  return 0;
+}
+              ]])],
+              [gl_cv_func_log1p_ieee=yes],
+              [gl_cv_func_log1p_ieee=no],
+              [gl_cv_func_log1p_ieee="guessing no"])
+            LIBS="$save_LIBS"
+          ])
+        case "$gl_cv_func_log1p_ieee" in
+          *yes) ;;
+          *) REPLACE_LOG1P=1 ;;
+        esac
+      fi
+    ])
+  else
     HAVE_LOG1P=0
+  fi
+  if test $HAVE_LOG1P = 0 || test $REPLACE_LOG1P = 1; then
     dnl Find libraries needed to link lib/log1p.c.
     AC_REQUIRE([gl_FUNC_ISNAND])
     AC_REQUIRE([gl_FUNC_LOG])
index 522be0b..d832e58 100644 (file)
@@ -1,4 +1,4 @@
-# math_h.m4 serial 98
+# math_h.m4 serial 99
 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,
@@ -270,6 +270,7 @@ AC_DEFUN([gl_MATH_H_DEFAULTS],
   REPLACE_LOG=0;               AC_SUBST([REPLACE_LOG])
   REPLACE_LOGF=0;              AC_SUBST([REPLACE_LOGF])
   REPLACE_LOGL=0;              AC_SUBST([REPLACE_LOGL])
+  REPLACE_LOG1P=0;             AC_SUBST([REPLACE_LOG1P])
   REPLACE_LOG1PF=0;            AC_SUBST([REPLACE_LOG1PF])
   REPLACE_MODF=0;              AC_SUBST([REPLACE_MODF])
   REPLACE_MODFF=0;             AC_SUBST([REPLACE_MODFF])
index e055026..57f8ff5 100644 (file)
@@ -9,13 +9,13 @@ m4/mathfunc.m4
 Depends-on:
 math
 extensions
-isnand          [test $HAVE_LOG1P = 0]
-log             [test $HAVE_LOG1P = 0]
-round           [test $HAVE_LOG1P = 0]
+isnand          [test $HAVE_LOG1P = 0 || test $REPLACE_LOG1P = 1]
+log             [test $HAVE_LOG1P = 0 || test $REPLACE_LOG1P = 1]
+round           [test $HAVE_LOG1P = 0 || test $REPLACE_LOG1P = 1]
 
 configure.ac:
 gl_FUNC_LOG1P
-if test $HAVE_LOG1P = 0; then
+if test $HAVE_LOG1P = 0 || test $REPLACE_LOG1P = 1; then
   AC_LIBOBJ([log1p])
 fi
 gl_MATH_MODULE_INDICATOR([log1p])
index b76096e..7a0aa9b 100644 (file)
@@ -2,12 +2,16 @@ Description:
 log1p() function according to ISO C 99 with IEC 60559.
 
 Files:
+m4/log1p-ieee.m4
+m4/minus-zero.m4
+m4/signbit.m4
 
 Depends-on:
 log1p
 fpieee
 
 configure.ac:
+gl_FUNC_LOG1P_IEEE
 
 Makefile.am:
 
index 16950da..cbd86cd 100644 (file)
@@ -238,6 +238,7 @@ math.h: math.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(
              -e 's|@''REPLACE_LOG''@|$(REPLACE_LOG)|g' \
              -e 's|@''REPLACE_LOGF''@|$(REPLACE_LOGF)|g' \
              -e 's|@''REPLACE_LOGL''@|$(REPLACE_LOGL)|g' \
+             -e 's|@''REPLACE_LOG1P''@|$(REPLACE_LOG1P)|g' \
              -e 's|@''REPLACE_LOG1PF''@|$(REPLACE_LOG1PF)|g' \
              -e 's|@''REPLACE_MODF''@|$(REPLACE_MODF)|g' \
              -e 's|@''REPLACE_MODFF''@|$(REPLACE_MODFF)|g' \