From aa42b5455c7a66de3882ba5870fee8abeb379498 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Fri, 9 Mar 2012 02:14:26 +0100 Subject: [PATCH] exp2l-ieee: Work around test failure on OpenBSD 4.9 and IRIX 6.5. * m4/exp2l-ieee.m4: New file. * m4/exp2l.m4 (gl_FUNC_EXP2L): If gl_FUNC_EXP2L_IEEE is present, test whether exp2l works with a NaN argument and with a negative infinity argument. Replace it if not. * lib/math.in.h (exp2l): Override if REPLACE_EXP2L is 1. * m4/math_h.m4 (gl_MATH_H_DEFAULTS): Initialize REPLACE_EXP2L. * modules/math (Makefile.am): Substitute REPLACE_EXP2L. * modules/exp2l (configure.ac): Consider REPLACE_EXP2L. (Depends-on): Update conditions. * modules/exp2l-ieee (Files): Add m4/exp2l-ieee.m4. (configure.ac): Invoke gl_FUNC_EXP2L_IEEE. * doc/posix-functions/exp2l.texi: Mention the exp2l-ieee module. --- ChangeLog | 14 ++++++++++++ doc/posix-functions/exp2l.texi | 14 ++++++++++-- lib/math.in.h | 15 ++++++++++--- m4/exp2l-ieee.m4 | 15 +++++++++++++ m4/exp2l.m4 | 50 +++++++++++++++++++++++++++++++++++++++++- m4/math_h.m4 | 3 ++- modules/exp2l | 12 +++++----- modules/exp2l-ieee | 2 ++ modules/math | 1 + 9 files changed, 113 insertions(+), 13 deletions(-) create mode 100644 m4/exp2l-ieee.m4 diff --git a/ChangeLog b/ChangeLog index 1fd76a722..ac139515a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,19 @@ 2012-03-08 Bruno Haible + exp2l-ieee: Work around test failure on OpenBSD 4.9 and IRIX 6.5. + * m4/exp2l-ieee.m4: New file. + * m4/exp2l.m4 (gl_FUNC_EXP2L): If gl_FUNC_EXP2L_IEEE is present, + test whether exp2l works with a NaN argument and with a negative + infinity argument. Replace it if not. + * lib/math.in.h (exp2l): Override if REPLACE_EXP2L is 1. + * m4/math_h.m4 (gl_MATH_H_DEFAULTS): Initialize REPLACE_EXP2L. + * modules/math (Makefile.am): Substitute REPLACE_EXP2L. + * modules/exp2l (configure.ac): Consider REPLACE_EXP2L. + (Depends-on): Update conditions. + * modules/exp2l-ieee (Files): Add m4/exp2l-ieee.m4. + (configure.ac): Invoke gl_FUNC_EXP2L_IEEE. + * doc/posix-functions/exp2l.texi: Mention the exp2l-ieee module. + Tests for module 'exp2l-ieee'. * modules/exp2l-ieee-tests: New file. * tests/test-exp2l-ieee.c: New file. diff --git a/doc/posix-functions/exp2l.texi b/doc/posix-functions/exp2l.texi index 8e963de8a..3cb997a4c 100644 --- a/doc/posix-functions/exp2l.texi +++ b/doc/posix-functions/exp2l.texi @@ -4,9 +4,9 @@ POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/exp2l.html} -Gnulib module: exp2l +Gnulib module: exp2l or exp2l-ieee -Portability problems fixed by Gnulib: +Portability problems fixed by either Gnulib module @code{exp2l} or @code{exp2l-ieee}: @itemize @item This function is missing on some platforms: @@ -16,6 +16,16 @@ This function is not declared on some platforms: IRIX 6.5. @end itemize +Portability problems fixed by Gnulib module @code{exp2l-ieee}: +@itemize +@item +This function returns a wrong value for a NaN argument on some platforms: +OpenBSD 4.9. +@item +This function returns a wrong value for a negative infinity argument on some platforms: +IRIX 6.5. +@end itemize + Portability problems not fixed by Gnulib: @itemize @end itemize diff --git a/lib/math.in.h b/lib/math.in.h index a1f6aa71a..2dba028e7 100644 --- a/lib/math.in.h +++ b/lib/math.in.h @@ -570,11 +570,20 @@ _GL_WARN_ON_USE (exp2, "exp2 is unportable - " #endif #if @GNULIB_EXP2L@ -# if !@HAVE_DECL_EXP2L@ -# undef exp2l +# if @REPLACE_EXP2L@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef exp2l +# define exp2l rpl_exp2l +# endif +_GL_FUNCDECL_RPL (exp2l, long double, (long double x)); +_GL_CXXALIAS_RPL (exp2l, long double, (long double x)); +# else +# if !@HAVE_DECL_EXP2L@ +# undef exp2l _GL_FUNCDECL_SYS (exp2l, long double, (long double x)); -# endif +# endif _GL_CXXALIAS_SYS (exp2l, long double, (long double x)); +# endif _GL_CXXALIASWARN (exp2l); #elif defined GNULIB_POSIXCHECK # undef exp2l diff --git a/m4/exp2l-ieee.m4 b/m4/exp2l-ieee.m4 new file mode 100644 index 000000000..7a6a159a0 --- /dev/null +++ b/m4/exp2l-ieee.m4 @@ -0,0 +1,15 @@ +# exp2l-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 exp2l.m4 and not inlined in the +dnl module description), so that gl_FUNC_EXP2L can test whether 'aclocal' has +dnl found uses of this macro. + +AC_DEFUN([gl_FUNC_EXP2L_IEEE], +[ + m4_divert_text([INIT_PREPARE], [gl_exp2l_required=ieee]) + AC_REQUIRE([gl_FUNC_EXP2L]) +]) diff --git a/m4/exp2l.m4 b/m4/exp2l.m4 index 333e23704..605cd14c7 100644 --- a/m4/exp2l.m4 +++ b/m4/exp2l.m4 @@ -1,4 +1,4 @@ -# exp2l.m4 serial 1 +# exp2l.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 @@ dnl with or without modifications, as long as this notice is preserved. AC_DEFUN([gl_FUNC_EXP2L], [ + m4_divert_text([DEFAULTS], [gl_exp2l_required=plain]) AC_REQUIRE([gl_MATH_H_DEFAULTS]) AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE]) AC_REQUIRE([gl_FUNC_EXP2]) @@ -25,9 +26,56 @@ AC_DEFUN([gl_FUNC_EXP2L], dnl Also check whether it's declared. dnl IRIX 6.5 has exp2l() in libm but doesn't declare it in . AC_CHECK_DECL([exp2l], , [HAVE_DECL_EXP2L=0], [[#include ]]) + m4_ifdef([gl_FUNC_EXP2L_IEEE], [ + if test $gl_exp2l_required = ieee && test $REPLACE_EXP2L = 0; then + AC_CACHE_CHECK([whether exp2l works according to ISO C 99 with IEC 60559], + [gl_cv_func_exp2l_ieee], + [ + save_LIBS="$LIBS" + LIBS="$LIBS $EXP2L_LIBM" + AC_RUN_IFELSE( + [AC_LANG_SOURCE([[ +#ifndef __NO_MATH_INLINES +# define __NO_MATH_INLINES 1 /* for glibc */ +#endif +#include +#undef exp2l +extern +#ifdef __cplusplus +"C" +#endif +long double exp2l (long double); +static long double dummy (long double x) { return 0; } +static long double zero; +int main (int argc, char *argv[]) +{ + long double (*my_exp2l) (long double) = argc ? exp2l : dummy; + int result = 0; + /* This test fails on OpenBSD 4.9, where exp2l(NaN) = 0.0. */ + if (exp2l (zero / zero) == 0.0L) + result |= 1; + /* This test fails on IRIX 6.5, where exp2l(-Inf) = 1.0. */ + if (!(exp2l (-1.0L / zero) == 0.0L)) + result |= 2; + return result; +} + ]])], + [gl_cv_func_exp2l_ieee=yes], + [gl_cv_func_exp2l_ieee=no], + [gl_cv_func_exp2l_ieee="guessing no"]) + LIBS="$save_LIBS" + ]) + case "$gl_cv_func_exp2l_ieee" in + *yes) ;; + *) REPLACE_EXP2L=1 ;; + esac + fi + ]) else HAVE_EXP2L=0 HAVE_DECL_EXP2L=0 + fi + if test $HAVE_EXP2L = 0 || test $REPLACE_EXP2L = 1; then dnl Find libraries needed to link lib/exp2l.c. if test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1; then EXP2L_LIBM="$EXP2_LIBM" diff --git a/m4/math_h.m4 b/m4/math_h.m4 index 5eed504ee..953ad1938 100644 --- a/m4/math_h.m4 +++ b/m4/math_h.m4 @@ -1,4 +1,4 @@ -# math_h.m4 serial 91 +# math_h.m4 serial 92 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, @@ -237,6 +237,7 @@ AC_DEFUN([gl_MATH_H_DEFAULTS], REPLACE_EXPM1=0; AC_SUBST([REPLACE_EXPM1]) REPLACE_EXPM1F=0; AC_SUBST([REPLACE_EXPM1F]) REPLACE_EXP2=0; AC_SUBST([REPLACE_EXP2]) + REPLACE_EXP2L=0; AC_SUBST([REPLACE_EXP2L]) 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/exp2l b/modules/exp2l index 709df7496..0314b46d7 100644 --- a/modules/exp2l +++ b/modules/exp2l @@ -9,15 +9,15 @@ m4/exp2l.m4 Depends-on: math extensions -exp2 [test $HAVE_EXP2L = 0 && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1] -float [test $HAVE_EXP2L = 0 && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 0] -isnanl [test $HAVE_EXP2L = 0 && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 0] -roundl [test $HAVE_EXP2L = 0 && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 0] -ldexpl [test $HAVE_EXP2L = 0 && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 0] +exp2 [{ test $HAVE_EXP2L = 0 || test $REPLACE_EXP2L = 1; } && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1] +float [{ test $HAVE_EXP2L = 0 || test $REPLACE_EXP2L = 1; } && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 0] +isnanl [{ test $HAVE_EXP2L = 0 || test $REPLACE_EXP2L = 1; } && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 0] +roundl [{ test $HAVE_EXP2L = 0 || test $REPLACE_EXP2L = 1; } && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 0] +ldexpl [{ test $HAVE_EXP2L = 0 || test $REPLACE_EXP2L = 1; } && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 0] configure.ac: gl_FUNC_EXP2L -if test $HAVE_EXP2L = 0; then +if test $HAVE_EXP2L = 0 || test $REPLACE_EXP2L = 1; then AC_LIBOBJ([exp2l]) AC_LIBOBJ([expl-table]) fi diff --git a/modules/exp2l-ieee b/modules/exp2l-ieee index af4c6eebc..e94070f79 100644 --- a/modules/exp2l-ieee +++ b/modules/exp2l-ieee @@ -2,12 +2,14 @@ Description: exp2l() function according to ISO C 99 with IEC 60559. Files: +m4/exp2l-ieee.m4 Depends-on: exp2l fpieee configure.ac: +gl_FUNC_EXP2L_IEEE Makefile.am: diff --git a/modules/math b/modules/math index e29d178c1..74671719e 100644 --- a/modules/math +++ b/modules/math @@ -205,6 +205,7 @@ math.h: math.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $( -e 's|@''REPLACE_EXPM1''@|$(REPLACE_EXPM1)|g' \ -e 's|@''REPLACE_EXPM1F''@|$(REPLACE_EXPM1F)|g' \ -e 's|@''REPLACE_EXP2''@|$(REPLACE_EXP2)|g' \ + -e 's|@''REPLACE_EXP2L''@|$(REPLACE_EXP2L)|g' \ -e 's|@''REPLACE_FABSL''@|$(REPLACE_FABSL)|g' \ -e 's|@''REPLACE_FLOOR''@|$(REPLACE_FLOOR)|g' \ -e 's|@''REPLACE_FLOORF''@|$(REPLACE_FLOORF)|g' \ -- 2.11.0