changeset 16588:6312b64c2c23

New module 'expm1-ieee'. * modules/expm1-ieee: New file. * m4/expm1-ieee.m4: New file. * m4/expm1.m4 (gl_FUNC_EXPM1): If gl_FUNC_EXPM1_IEEE is present, test whether expm1 works with a minus zero argument. Replace it if not. * lib/math.in.h (expm1): Override if REPLACE_EXPM1 is 1. * m4/math_h.m4 (gl_MATH_H_DEFAULTS): Initialize REPLACE_EXPM1. * modules/math (Makefile.am): Substitute REPLACE_EXPM1. * modules/expm1 (configure.ac): Consider REPLACE_EXPM1. (Depends-on): Update conditions. * doc/posix-functions/expm1.texi: Mention the expm1-ieee module and the AIX problem.
author Bruno Haible <bruno@clisp.org>
date Wed, 07 Mar 2012 00:38:50 +0100
parents d71dacc1f7e0
children 338bc8a6f860
files ChangeLog doc/posix-functions/expm1.texi lib/math.in.h m4/expm1-ieee.m4 m4/expm1.m4 m4/math_h.m4 modules/expm1 modules/expm1-ieee modules/math
diffstat 9 files changed, 131 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2012-03-06  Bruno Haible  <bruno@clisp.org>
+
+	New module 'expm1-ieee'.
+	* modules/expm1-ieee: New file.
+	* m4/expm1-ieee.m4: New file.
+	* m4/expm1.m4 (gl_FUNC_EXPM1): If gl_FUNC_EXPM1_IEEE is present, test
+	whether expm1 works with a minus zero argument. Replace it if not.
+	* lib/math.in.h (expm1): Override if REPLACE_EXPM1 is 1.
+	* m4/math_h.m4 (gl_MATH_H_DEFAULTS): Initialize REPLACE_EXPM1.
+	* modules/math (Makefile.am): Substitute REPLACE_EXPM1.
+	* modules/expm1 (configure.ac): Consider REPLACE_EXPM1.
+	(Depends-on): Update conditions.
+	* doc/posix-functions/expm1.texi: Mention the expm1-ieee module and the
+	AIX problem.
+
 2012-03-06  Bruno Haible  <bruno@clisp.org>
 
 	Work around expm1f bug on IRIX 6.5.
--- a/doc/posix-functions/expm1.texi
+++ b/doc/posix-functions/expm1.texi
@@ -4,15 +4,23 @@
 
 POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/expm1.html}
 
-Gnulib module: expm1
+Gnulib module: expm1 or expm1-ieee
 
-Portability problems fixed by Gnulib:
+Portability problems fixed by either Gnulib module @code{expm1} or @code{expm1-ieee}:
 @itemize
 @item
 This function is missing on some platforms:
 Minix 3.1.8, mingw, MSVC 9.
 @end itemize
 
+Portability problems fixed by Gnulib module @code{expm1-ieee}:
+@itemize
+@item
+This function has problems when the first argument is minus zero on some
+platforms:
+AIX 7.1.
+@end itemize
+
 Portability problems not fixed by Gnulib:
 @itemize
 @end itemize
--- a/lib/math.in.h
+++ b/lib/math.in.h
@@ -556,10 +556,19 @@
 #endif
 
 #if @GNULIB_EXPM1@
-# if !@HAVE_EXPM1@
+# if @REPLACE_EXPM1@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef expm1
+#   define expm1 rpl_expm1
+#  endif
+_GL_FUNCDECL_RPL (expm1, double, (double x));
+_GL_CXXALIAS_RPL (expm1, double, (double x));
+# else
+#  if !@HAVE_EXPM1@
 _GL_FUNCDECL_SYS (expm1, double, (double x));
+#  endif
+_GL_CXXALIAS_SYS (expm1, double, (double x));
 # endif
-_GL_CXXALIAS_SYS (expm1, double, (double x));
 _GL_CXXALIASWARN (expm1);
 #elif defined GNULIB_POSIXCHECK
 # undef expm1
new file mode 100644
--- /dev/null
+++ b/m4/expm1-ieee.m4
@@ -0,0 +1,15 @@
+# expm1-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 expm1.m4 and not inlined in the
+dnl module description), so that gl_FUNC_EXPM1 can test whether 'aclocal' has
+dnl found uses of this macro.
+
+AC_DEFUN([gl_FUNC_EXPM1_IEEE],
+[
+  m4_divert_text([INIT_PREPARE], [gl_expm1_required=ieee])
+  AC_REQUIRE([gl_FUNC_EXPM1])
+])
--- a/m4/expm1.m4
+++ b/m4/expm1.m4
@@ -1,4 +1,4 @@
-# expm1.m4 serial 1
+# expm1.m4 serial 2
 dnl Copyright (C) 2010-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 @@
 
 AC_DEFUN([gl_FUNC_EXPM1],
 [
+  m4_divert_text([DEFAULTS], [gl_expm1_required=plain])
   AC_REQUIRE([gl_MATH_H_DEFAULTS])
 
   dnl Persuade glibc <math.h> to declare expm1().
@@ -52,9 +53,49 @@
       EXPM1_LIBM=-lm
     fi
   fi
-  if test $gl_cv_func_expm1_no_libm = no \
-     && test $gl_cv_func_expm1_in_libm = no; then
+  if test $gl_cv_func_expm1_no_libm = yes \
+     || test $gl_cv_func_expm1_in_libm = yes; then
+    :
+    m4_ifdef([gl_FUNC_EXPM1_IEEE], [
+      if test $gl_expm1_required = ieee && test $REPLACE_EXPM1 = 0; then
+        AC_CACHE_CHECK([whether expm1 works according to ISO C 99 with IEC 60559],
+          [gl_cv_func_expm1_ieee],
+          [
+            save_LIBS="$LIBS"
+            LIBS="$LIBS $EXPM1_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_expm1) (double) = argc ? expm1 : dummy;
+  double y = my_expm1 (minus_zerod);
+  if (!(y == 0.0) || (signbitd (minus_zerod) && !signbitd (y)))
+    return 1;
+  return 0;
+}
+              ]])],
+              [gl_cv_func_expm1_ieee=yes],
+              [gl_cv_func_expm1_ieee=no],
+              [gl_cv_func_expm1_ieee="guessing no"])
+            LIBS="$save_LIBS"
+          ])
+        case "$gl_cv_func_expm1_ieee" in
+          *yes) ;;
+          *) REPLACE_EXPM1=1 ;;
+        esac
+      fi
+    ])
+  else
     HAVE_EXPM1=0
+  fi
+  if test $HAVE_EXPM1 = 0 || test $REPLACE_EXPM1 = 1; then
     dnl Find libraries needed to link lib/expm1.c.
     AC_REQUIRE([gl_FUNC_ISNAND])
     AC_REQUIRE([gl_FUNC_EXP])
--- a/m4/math_h.m4
+++ b/m4/math_h.m4
@@ -1,4 +1,4 @@
-# math_h.m4 serial 83
+# math_h.m4 serial 84
 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,
@@ -227,6 +227,7 @@
   REPLACE_CEIL=0;              AC_SUBST([REPLACE_CEIL])
   REPLACE_CEILF=0;             AC_SUBST([REPLACE_CEILF])
   REPLACE_CEILL=0;             AC_SUBST([REPLACE_CEILL])
+  REPLACE_EXPM1=0;             AC_SUBST([REPLACE_EXPM1])
   REPLACE_EXPM1F=0;            AC_SUBST([REPLACE_EXPM1F])
   REPLACE_FABSL=0;             AC_SUBST([REPLACE_FABSL])
   REPLACE_FLOOR=0;             AC_SUBST([REPLACE_FLOOR])
--- a/modules/expm1
+++ b/modules/expm1
@@ -9,14 +9,14 @@
 Depends-on:
 math
 extensions
-isnand          [test $HAVE_EXPM1 = 0]
-exp             [test $HAVE_EXPM1 = 0]
-round           [test $HAVE_EXPM1 = 0]
-ldexp           [test $HAVE_EXPM1 = 0]
+isnand          [test $HAVE_EXPM1 = 0 || test $REPLACE_EXPM1 = 1]
+exp             [test $HAVE_EXPM1 = 0 || test $REPLACE_EXPM1 = 1]
+round           [test $HAVE_EXPM1 = 0 || test $REPLACE_EXPM1 = 1]
+ldexp           [test $HAVE_EXPM1 = 0 || test $REPLACE_EXPM1 = 1]
 
 configure.ac:
 gl_FUNC_EXPM1
-if test $HAVE_EXPM1 = 0; then
+if test $HAVE_EXPM1 = 0 || test $REPLACE_EXPM1 = 1; then
   AC_LIBOBJ([expm1])
 fi
 gl_MATH_MODULE_INDICATOR([expm1])
new file mode 100644
--- /dev/null
+++ b/modules/expm1-ieee
@@ -0,0 +1,28 @@
+Description:
+expm1() function according to ISO C 99 with IEC 60559.
+
+Files:
+m4/expm1-ieee.m4
+m4/minus-zero.m4
+m4/signbit.m4
+
+Depends-on:
+expm1
+fpieee
+
+configure.ac:
+gl_FUNC_EXPM1_IEEE
+
+Makefile.am:
+
+Include:
+<math.h>
+
+Link:
+$(EXPM1_LIBM)
+
+License:
+LGPL
+
+Maintainer:
+Bruno Haible
--- a/modules/math
+++ b/modules/math
@@ -196,6 +196,7 @@
 	      -e 's|@''REPLACE_CEIL''@|$(REPLACE_CEIL)|g' \
 	      -e 's|@''REPLACE_CEILF''@|$(REPLACE_CEILF)|g' \
 	      -e 's|@''REPLACE_CEILL''@|$(REPLACE_CEILL)|g' \
+	      -e 's|@''REPLACE_EXPM1''@|$(REPLACE_EXPM1)|g' \
 	      -e 's|@''REPLACE_EXPM1F''@|$(REPLACE_EXPM1F)|g' \
 	      -e 's|@''REPLACE_FABSL''@|$(REPLACE_FABSL)|g' \
 	      -e 's|@''REPLACE_FLOOR''@|$(REPLACE_FLOOR)|g' \