changeset 16587:d71dacc1f7e0

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.
author Bruno Haible <bruno@clisp.org>
date Tue, 06 Mar 2012 23:25:51 +0100
parents 79c22773e9b7
children 6312b64c2c23
files ChangeLog doc/posix-functions/expm1f.texi lib/math.in.h m4/expm1f.m4 m4/math_h.m4 modules/expm1f modules/math
diffstat 7 files changed, 75 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+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'.
--- a/doc/posix-functions/expm1f.texi
+++ b/doc/posix-functions/expm1f.texi
@@ -11,6 +11,9 @@
 @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:
--- a/lib/math.in.h
+++ b/lib/math.in.h
@@ -533,10 +533,19 @@
 
 
 #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
+_GL_CXXALIAS_SYS (expm1f, float, (float x));
 # endif
-_GL_CXXALIAS_SYS (expm1f, float, (float x));
 _GL_CXXALIASWARN (expm1f);
 #elif defined GNULIB_POSIXCHECK
 # undef expm1f
--- a/m4/expm1f.m4
+++ b/m4/expm1f.m4
@@ -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 @@
   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
+        ])
+    ])
+])
--- a/m4/math_h.m4
+++ b/m4/math_h.m4
@@ -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 @@
   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])
--- a/modules/expm1f
+++ b/modules/expm1f
@@ -8,11 +8,11 @@
 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])
--- 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_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' \