From f068ad7807118fd201763a73b0f27a3f73827f50 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sun, 1 Apr 2012 14:41:57 +0200 Subject: [PATCH] log10l: Work around AIX 5.1, IRIX 6.5, OSF/1 5.1 bug. * lib/math.in.h (log10l): Override if REPLACE_LOG10L is 1. * lib/log10l.c (log10l): If log10l exists, use it and provide just the workaround. * m4/log10l.m4 (gl_FUNC_LOG10L_WORKS): New macro. (gl_FUNC_LOG10L): Invoke it. Set REPLACE_LOG10L. * m4/math_h.m4 (gl_MATH_H_DEFAULTS): Initialize REPLACE_LOG10L. * modules/math (Makefile.am): Substitute REPLACE_LOG10L. * modules/log10l (configure.ac): Consider REPLACE_LOG10L. (Depends-on): Update conditions. * doc/posix-functions/log10l.texi: Mention the MSVC9, AIX 5.1, IRIX 6.5, OSF/1 5.1 problems. --- ChangeLog | 15 +++++++++ doc/posix-functions/log10l.texi | 13 ++++++-- lib/log10l.c | 13 ++++++++ lib/math.in.h | 15 +++++++-- m4/log10l.m4 | 67 +++++++++++++++++++++++++++++++++++++++-- m4/math_h.m4 | 3 +- modules/log10l | 6 ++-- modules/math | 1 + 8 files changed, 121 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index 06eb7fb59..d5d638685 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,20 @@ 2012-04-01 Bruno Haible + log10l: Work around AIX 5.1, IRIX 6.5, OSF/1 5.1 bug. + * lib/math.in.h (log10l): Override if REPLACE_LOG10L is 1. + * lib/log10l.c (log10l): If log10l exists, use it and provide just the + workaround. + * m4/log10l.m4 (gl_FUNC_LOG10L_WORKS): New macro. + (gl_FUNC_LOG10L): Invoke it. Set REPLACE_LOG10L. + * m4/math_h.m4 (gl_MATH_H_DEFAULTS): Initialize REPLACE_LOG10L. + * modules/math (Makefile.am): Substitute REPLACE_LOG10L. + * modules/log10l (configure.ac): Consider REPLACE_LOG10L. + (Depends-on): Update conditions. + * doc/posix-functions/log10l.texi: Mention the MSVC9, AIX 5.1, + IRIX 6.5, OSF/1 5.1 problems. + +2012-04-01 Bruno Haible + log10f: Work around OSF/1 5.1 bug. * lib/math.in.h (log10f): Override if REPLACE_LOG10F is 1. * lib/log10f.c (log10f): If logf exists, use it and provide just the diff --git a/doc/posix-functions/log10l.texi b/doc/posix-functions/log10l.texi index 1f29c1b4d..eb8eec8cd 100644 --- a/doc/posix-functions/log10l.texi +++ b/doc/posix-functions/log10l.texi @@ -10,10 +10,19 @@ Portability problems fixed by Gnulib: @itemize @item This function is missing on some platforms: -FreeBSD 6.0, NetBSD 5.0, OpenBSD 3.8, Minix 3.1.8, HP-UX 11, IRIX 6.5, Solaris 9, Cygwin, Interix 3.5, BeOS. +FreeBSD 6.0, NetBSD 5.0, OpenBSD 3.8, Minix 3.1.8, HP-UX 11, older IRIX 6.5, Solaris 9, Cygwin, Interix 3.5, BeOS. @item -This function is not declared on some platforms: +This function is only defined as a macro with arguments on some platforms: +MSVC 9. +@item +This function is not declared and does not work on some platforms: AIX 5.1. +@item +This function returns a wrong value for a minus zero argument on some platforms: +OSF/1 5.1. +@item +This function returns an unnormalized negative infinity for a minus zero argument on some platforms: +IRIX 6.5. @end itemize Portability problems not fixed by Gnulib: diff --git a/lib/log10l.c b/lib/log10l.c index ecaacb217..f10853890 100644 --- a/lib/log10l.c +++ b/lib/log10l.c @@ -27,6 +27,19 @@ log10l (long double x) return log10 (x); } +#elif HAVE_LOG10L + +long double +log10l (long double x) +# undef log10l +{ + /* Work around the OSF/1 5.1 bug. */ + if (x == 0.0L) + /* Return -Infinity. */ + return -1.0L / 0.0L; + return log10l (x); +} + #else /* 1 / log(10) */ diff --git a/lib/math.in.h b/lib/math.in.h index 335238df5..f5c5f0391 100644 --- a/lib/math.in.h +++ b/lib/math.in.h @@ -1235,11 +1235,20 @@ _GL_WARN_ON_USE (log10, "log10 has portability problems - " #endif #if @GNULIB_LOG10L@ -# if !@HAVE_LOG10L@ || !@HAVE_DECL_LOG10L@ -# undef log10l +# if @REPLACE_LOG10L@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef log10l +# define log10l rpl_log10l +# endif +_GL_FUNCDECL_RPL (log10l, long double, (long double x)); +_GL_CXXALIAS_RPL (log10l, long double, (long double x)); +# else +# if !@HAVE_LOG10L@ || !@HAVE_DECL_LOG10L@ +# undef log10l _GL_FUNCDECL_SYS (log10l, long double, (long double x)); -# endif +# endif _GL_CXXALIAS_SYS (log10l, long double, (long double x)); +# endif _GL_CXXALIASWARN (log10l); #elif defined GNULIB_POSIXCHECK # undef log10l diff --git a/m4/log10l.m4 b/m4/log10l.m4 index c124f891c..df614b167 100644 --- a/m4/log10l.m4 +++ b/m4/log10l.m4 @@ -1,4 +1,4 @@ -# log10l.m4 serial 2 +# log10l.m4 serial 3 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, @@ -24,14 +24,75 @@ AC_DEFUN([gl_FUNC_LOG10L], LIBS="$save_LIBS" if test $ac_cv_func_log10l = yes; then LOG10L_LIBM="$LOG10_LIBM" + + save_LIBS="$LIBS" + LIBS="$LIBS $LOG10L_LIBM" + gl_FUNC_LOG10L_WORKS + LIBS="$save_LIBS" + case "$gl_cv_func_log10l_works" in + *yes) ;; + *) REPLACE_LOG10L=1 ;; + esac else HAVE_LOG10L=0 + fi + if test $HAVE_LOG10L = 0 || test $REPLACE_LOG10L = 1; then if test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1; then LOG10L_LIBM="$LOG10_LIBM" else - AC_REQUIRE([gl_FUNC_LOGL]) - LOG10L_LIBM="$LOGL_LIBM" + if test $HAVE_LOG10L = 0; then + AC_REQUIRE([gl_FUNC_LOGL]) + LOG10L_LIBM="$LOGL_LIBM" + fi fi fi AC_SUBST([LOG10L_LIBM]) ]) + +dnl Test whether log10l() works. +dnl On OSF/1 5.1, log10l(-0.0L) is NaN. +dnl On IRIX 6.5, log10l(-0.0L) is an unnormalized negative infinity +dnl 0xFFF00000000000007FF0000000000000, should be +dnl 0xFFF00000000000000000000000000000. +dnl On AIX 5.1, log10l(-0.0L) is finite if it's not the first log10l call +dnl in the program. +AC_DEFUN([gl_FUNC_LOG10L_WORKS], +[ + AC_REQUIRE([AC_PROG_CC]) + AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles + AC_CACHE_CHECK([whether log10l works], [gl_cv_func_log10l_works], + [ + AC_RUN_IFELSE( + [AC_LANG_SOURCE([[ +#include +#ifndef log10l /* for AIX */ +extern +#ifdef __cplusplus +"C" +#endif +long double log10l (long double); +#endif +volatile long double x; +long double y; +int main () +{ + /* Dummy call, to trigger the AIX 5.1 bug. */ + x = 0.6L; + y = log10l (x); + /* This test fails on AIX 5.1, IRIX 6.5, OSF/1 5.1. */ + x = -0.0L; + y = log10l (x); + if (!(y + y == y)) + return 1; + return 0; +} +]])], + [gl_cv_func_log10l_works=yes], + [gl_cv_func_log10l_works=no], + [case "$host_os" in + aix* | irix* | osf*) gl_cv_func_log10l_works="guessing no";; + *) gl_cv_func_log10l_works="guessing yes";; + esac + ]) + ]) +]) diff --git a/m4/math_h.m4 b/m4/math_h.m4 index 5bfa28c5d..a24d35289 100644 --- a/m4/math_h.m4 +++ b/m4/math_h.m4 @@ -1,4 +1,4 @@ -# math_h.m4 serial 106 +# math_h.m4 serial 107 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, @@ -280,6 +280,7 @@ AC_DEFUN([gl_MATH_H_DEFAULTS], REPLACE_LOGL=0; AC_SUBST([REPLACE_LOGL]) REPLACE_LOG10=0; AC_SUBST([REPLACE_LOG10]) REPLACE_LOG10F=0; AC_SUBST([REPLACE_LOG10F]) + REPLACE_LOG10L=0; AC_SUBST([REPLACE_LOG10L]) REPLACE_LOG1P=0; AC_SUBST([REPLACE_LOG1P]) REPLACE_LOG1PF=0; AC_SUBST([REPLACE_LOG1PF]) REPLACE_LOG1PL=0; AC_SUBST([REPLACE_LOG1PL]) diff --git a/modules/log10l b/modules/log10l index 16b49cd68..cad6bbeed 100644 --- a/modules/log10l +++ b/modules/log10l @@ -8,12 +8,12 @@ m4/log10l.m4 Depends-on: math extensions -log10 [test $HAVE_LOG10L = 0 && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1] -logl [test $HAVE_LOG10L = 0 && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 0] +log10 [{ test $HAVE_LOG10L = 0 || test $REPLACE_LOG10L = 1; } && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1] +logl [{ test $HAVE_LOG10L = 0 || test $REPLACE_LOG10L = 1; } && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 0] configure.ac: gl_FUNC_LOG10L -if test $HAVE_LOG10L = 0; then +if test $HAVE_LOG10L = 0 || test $REPLACE_LOG10L = 1; then AC_LIBOBJ([log10l]) fi gl_MATH_MODULE_INDICATOR([log10l]) diff --git a/modules/math b/modules/math index cb81a7dd4..68fe9586f 100644 --- a/modules/math +++ b/modules/math @@ -247,6 +247,7 @@ math.h: math.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $( -e 's|@''REPLACE_LOGL''@|$(REPLACE_LOGL)|g' \ -e 's|@''REPLACE_LOG10''@|$(REPLACE_LOG10)|g' \ -e 's|@''REPLACE_LOG10F''@|$(REPLACE_LOG10F)|g' \ + -e 's|@''REPLACE_LOG10L''@|$(REPLACE_LOG10L)|g' \ -e 's|@''REPLACE_LOG1P''@|$(REPLACE_LOG1P)|g' \ -e 's|@''REPLACE_LOG1PF''@|$(REPLACE_LOG1PF)|g' \ -e 's|@''REPLACE_LOG1PL''@|$(REPLACE_LOG1PL)|g' \ -- 2.11.0