From: Bruno Haible Date: Tue, 6 Mar 2012 22:25:51 +0000 (+0100) Subject: Work around expm1f bug on IRIX 6.5. X-Git-Tag: v0.1~939 X-Git-Url: http://erislabs.net/gitweb/?a=commitdiff_plain;h=7c193d625308bb806418c61ec9062fc22a29aeaf;p=gnulib.git 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. --- diff --git a/ChangeLog b/ChangeLog index a5f694814..f70e98ebe 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,18 @@ 2012-03-06 Bruno Haible + 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 + Tests for module 'expm1l'. * modules/expm1l-tests: New file. * tests/test-expm1l.c: New file. diff --git a/doc/posix-functions/expm1f.texi b/doc/posix-functions/expm1f.texi index 6023a837e..c86d8e885 100644 --- a/doc/posix-functions/expm1f.texi +++ b/doc/posix-functions/expm1f.texi @@ -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: diff --git a/lib/math.in.h b/lib/math.in.h index 5413d3a16..c57e48bb9 100644 --- a/lib/math.in.h +++ b/lib/math.in.h @@ -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 diff --git a/m4/expm1f.m4 b/m4/expm1f.m4 index f78262a47..04a0d7279 100644 --- 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 @@ 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 +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 + ]) + ]) +]) diff --git a/m4/math_h.m4 b/m4/math_h.m4 index d8e5ad7eb..f49fb232a 100644 --- 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 @@ 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]) diff --git a/modules/expm1f b/modules/expm1f index 823886ac8..7092e3a2e 100644 --- a/modules/expm1f +++ b/modules/expm1f @@ -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]) diff --git a/modules/math b/modules/math index da0e9bdf8..2c95248d6 100644 --- a/modules/math +++ b/modules/math @@ -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' \