Work around expm1f bug on IRIX 6.5.
authorBruno Haible <bruno@clisp.org>
Tue, 6 Mar 2012 22:25:51 +0000 (23:25 +0100)
committerBruno Haible <bruno@clisp.org>
Tue, 6 Mar 2012 23:05:20 +0000 (00:05 +0100)
* lib/math.in.h (expm1f): Override if REPLACE_EXPM1F is 1.
* m4/expm1f.m4 (gl_FUNC_EXPM1F_WORKS): New macro.
(gl_FUNC_EXPM1F): Invoke it. Set REPLACE_EXPM1F to 1 if expm1f() does
not work.
* m4/math_h.m4 (gl_MATH_H_DEFAULTS): Initialize REPLACE_EXPM1F.
* modules/math (Makefile.am): Substitute REPLACE_EXPM1F.
* modules/expm1f (configure.ac): Consider REPLACE_EXPM1F.
(Depends-on): Update conditions.
* doc/posix-functions/expm1f.texi: Mention the IRIX 6.5 bug.

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

index a5f6948..f70e98e 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,18 @@
 2012-03-06  Bruno Haible  <bruno@clisp.org>
 
+       Work around expm1f bug on IRIX 6.5.
+       * lib/math.in.h (expm1f): Override if REPLACE_EXPM1F is 1.
+       * m4/expm1f.m4 (gl_FUNC_EXPM1F_WORKS): New macro.
+       (gl_FUNC_EXPM1F): Invoke it. Set REPLACE_EXPM1F to 1 if expm1f() does
+       not work.
+       * m4/math_h.m4 (gl_MATH_H_DEFAULTS): Initialize REPLACE_EXPM1F.
+       * modules/math (Makefile.am): Substitute REPLACE_EXPM1F.
+       * modules/expm1f (configure.ac): Consider REPLACE_EXPM1F.
+       (Depends-on): Update conditions.
+       * doc/posix-functions/expm1f.texi: Mention the IRIX 6.5 bug.
+
+2012-03-06  Bruno Haible  <bruno@clisp.org>
+
        Tests for module 'expm1l'.
        * modules/expm1l-tests: New file.
        * tests/test-expm1l.c: New file.
index 6023a83..c86d8e8 100644 (file)
@@ -11,6 +11,9 @@ Portability problems fixed by Gnulib:
 @item
 This function is missing on some platforms:
 Minix 3.1.8, AIX 5.1, HP-UX 11, Solaris 9, mingw, MSVC 9.
+@item
+This function produces wrong results for arguments <= -17.32868 on some platforms:
+IRIX 6.5.
 @end itemize
 
 Portability problems not fixed by Gnulib:
index 5413d3a..c57e48b 100644 (file)
@@ -533,10 +533,19 @@ _GL_WARN_ON_USE (expl, "expl is unportable - "
 
 
 #if @GNULIB_EXPM1F@
-# if !@HAVE_EXPM1F@
+# if @REPLACE_EXPM1F@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef expm1f
+#   define expm1f rpl_expm1f
+#  endif
+_GL_FUNCDECL_RPL (expm1f, float, (float x));
+_GL_CXXALIAS_RPL (expm1f, float, (float x));
+# else
+#  if !@HAVE_EXPM1F@
 _GL_FUNCDECL_SYS (expm1f, float, (float x));
-# endif
+#  endif
 _GL_CXXALIAS_SYS (expm1f, float, (float x));
+# endif
 _GL_CXXALIASWARN (expm1f);
 #elif defined GNULIB_POSIXCHECK
 # undef expm1f
index f78262a..04a0d72 100644 (file)
@@ -1,4 +1,4 @@
-# expm1f.m4 serial 1
+# expm1f.m4 serial 2
 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,
@@ -20,10 +20,52 @@ AC_DEFUN([gl_FUNC_EXPM1F],
   LIBS="$save_LIBS"
   if test $ac_cv_func_expm1f = yes; then
     EXPM1F_LIBM="$EXPM1_LIBM"
+    save_LIBS="$LIBS"
+    LIBS="$LIBS $EXPM1F_LIBM"
+    gl_FUNC_EXPM1F_WORKS
+    LIBS="$save_LIBS"
+    case "$gl_cv_func_expm1f_works" in
+      *yes) ;;
+      *) REPLACE_EXPM1F=1 ;;
+    esac
   else
     HAVE_EXPM1F=0
+  fi
+  if test $HAVE_EXPM1F = 0 || test $REPLACE_EXPM1F = 1; then
     dnl Find libraries needed to link lib/expm1f.c.
     EXPM1F_LIBM="$EXPM1_LIBM"
   fi
   AC_SUBST([EXPM1F_LIBM])
 ])
+
+dnl Test whether expm1f() works.
+dnl On IRIX 6.5, for arguments <= -17.32868, it returns -5.6295e14.
+AC_DEFUN([gl_FUNC_EXPM1F_WORKS],
+[
+  AC_REQUIRE([AC_PROG_CC])
+  AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
+  AC_CACHE_CHECK([whether expm1f works], [gl_cv_func_expm1f_works],
+    [
+      AC_RUN_IFELSE(
+        [AC_LANG_SOURCE([[
+#include <math.h>
+volatile float x;
+float y;
+int main ()
+{
+  x = -100.0f;
+  y = expm1f (x);
+  if (y < -1.0f)
+    return 1;
+  return 0;
+}
+]])],
+        [gl_cv_func_expm1f_works=yes],
+        [gl_cv_func_expm1f_works=no],
+        [case "$host_os" in
+           irix*) gl_cv_func_expm1f_works="guessing no";;
+           *)     gl_cv_func_expm1f_works="guessing yes";;
+         esac
+        ])
+    ])
+])
index d8e5ad7..f49fb23 100644 (file)
@@ -1,4 +1,4 @@
-# math_h.m4 serial 82
+# math_h.m4 serial 83
 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 @@ AC_DEFUN([gl_MATH_H_DEFAULTS],
   REPLACE_CEIL=0;              AC_SUBST([REPLACE_CEIL])
   REPLACE_CEILF=0;             AC_SUBST([REPLACE_CEILF])
   REPLACE_CEILL=0;             AC_SUBST([REPLACE_CEILL])
+  REPLACE_EXPM1F=0;            AC_SUBST([REPLACE_EXPM1F])
   REPLACE_FABSL=0;             AC_SUBST([REPLACE_FABSL])
   REPLACE_FLOOR=0;             AC_SUBST([REPLACE_FLOOR])
   REPLACE_FLOORF=0;            AC_SUBST([REPLACE_FLOORF])
index 823886a..7092e3a 100644 (file)
@@ -8,11 +8,11 @@ m4/expm1f.m4
 Depends-on:
 math
 extensions
-expm1           [test $HAVE_EXPM1F = 0]
+expm1           [test $HAVE_EXPM1F = 0 || test $REPLACE_EXPM1F = 1]
 
 configure.ac:
 gl_FUNC_EXPM1F
-if test $HAVE_EXPM1F = 0; then
+if test $HAVE_EXPM1F = 0 || test $REPLACE_EXPM1F = 1; then
   AC_LIBOBJ([expm1f])
 fi
 gl_MATH_MODULE_INDICATOR([expm1f])
index da0e9bd..2c95248 100644 (file)
@@ -196,6 +196,7 @@ math.h: math.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(
              -e 's|@''REPLACE_CEIL''@|$(REPLACE_CEIL)|g' \
              -e 's|@''REPLACE_CEILF''@|$(REPLACE_CEILF)|g' \
              -e 's|@''REPLACE_CEILL''@|$(REPLACE_CEILL)|g' \
+             -e 's|@''REPLACE_EXPM1F''@|$(REPLACE_EXPM1F)|g' \
              -e 's|@''REPLACE_FABSL''@|$(REPLACE_FABSL)|g' \
              -e 's|@''REPLACE_FLOOR''@|$(REPLACE_FLOOR)|g' \
              -e 's|@''REPLACE_FLOORF''@|$(REPLACE_FLOORF)|g' \