# HG changeset patch # User Bruno Haible # Date 1331337348 -3600 # Node ID 2450f24b2cbc0cb04aa5110583f0dd63da8fd806 # Parent 45443deebb7d1f026495185cb00ce5fd0965b558 logf: Work around OSF/1 5.1 bug. * lib/math.in.h (logf): Override if REPLACE_LOGF is 1. * lib/logf.c (logf): If logf exists, use it and provide just the workaround. * m4/logf.m4 (gl_FUNC_LOGF_WORKS): New macro. (gl_FUNC_LOGF): Invoke it. Set REPLACE_LOGF. * m4/math_h.m4 (gl_MATH_H_DEFAULTS): Initialize REPLACE_LOGF. * modules/math (Makefile.am): Substitute REPLACE_LOGF. * modules/logf (configure.ac): Consider REPLACE_LOGF. (Depends-on): Update conditions. * doc/posix-functions/logf.texi: Mention the OSF/1 5.1 problem. diff --git a/ChangeLog b/ChangeLog --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2012-03-09 Bruno Haible + + logf: Work around OSF/1 5.1 bug. + * lib/math.in.h (logf): Override if REPLACE_LOGF is 1. + * lib/logf.c (logf): If logf exists, use it and provide just the + workaround. + * m4/logf.m4 (gl_FUNC_LOGF_WORKS): New macro. + (gl_FUNC_LOGF): Invoke it. Set REPLACE_LOGF. + * m4/math_h.m4 (gl_MATH_H_DEFAULTS): Initialize REPLACE_LOGF. + * modules/math (Makefile.am): Substitute REPLACE_LOGF. + * modules/logf (configure.ac): Consider REPLACE_LOGF. + (Depends-on): Update conditions. + * doc/posix-functions/logf.texi: Mention the OSF/1 5.1 problem. + 2012-03-09 Bruno Haible log: Work around OSF/1 5.1 bug. diff --git a/doc/posix-functions/logf.texi b/doc/posix-functions/logf.texi --- a/doc/posix-functions/logf.texi +++ b/doc/posix-functions/logf.texi @@ -14,6 +14,9 @@ @item This function is only defined as a macro with arguments on some platforms: MSVC 9. +@item +This function returns a wrong value for a minus zero argument on some platforms: +OSF/1 5.1. @end itemize Portability problems not fixed by Gnulib: diff --git a/lib/logf.c b/lib/logf.c --- a/lib/logf.c +++ b/lib/logf.c @@ -21,6 +21,15 @@ float logf (float x) +#undef logf { +#if HAVE_LOGF + /* Work around the OSF/1 5.1 bug. */ + if (x == 0.0f) + /* Return -Infinity. */ + return -1.0f / 0.0f; + return logf (x); +#else return (float) log ((double) x); +#endif } diff --git a/lib/math.in.h b/lib/math.in.h --- a/lib/math.in.h +++ b/lib/math.in.h @@ -1122,11 +1122,20 @@ #if @GNULIB_LOGF@ -# if !@HAVE_LOGF@ -# undef logf +# if @REPLACE_LOGF@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef logf +# define logf rpl_logf +# endif +_GL_FUNCDECL_RPL (logf, float, (float x)); +_GL_CXXALIAS_RPL (logf, float, (float x)); +# else +# if !@HAVE_LOGF@ +# undef logf _GL_FUNCDECL_SYS (logf, float, (float x)); +# endif +_GL_CXXALIAS_SYS (logf, float, (float x)); # endif -_GL_CXXALIAS_SYS (logf, float, (float x)); _GL_CXXALIASWARN (logf); #elif defined GNULIB_POSIXCHECK # undef logf diff --git a/m4/logf.m4 b/m4/logf.m4 --- a/m4/logf.m4 +++ b/m4/logf.m4 @@ -1,4 +1,4 @@ -# logf.m4 serial 2 +# logf.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, @@ -20,9 +20,54 @@ LIBS="$save_LIBS" if test $ac_cv_func_logf = yes; then LOGF_LIBM="$LOG_LIBM" + save_LIBS="$LIBS" + LIBS="$LIBS $LOGF_LIBM" + gl_FUNC_LOGF_WORKS + LIBS="$save_LIBS" + case "$gl_cv_func_logf_works" in + *yes) ;; + *) REPLACE_LOGF=1 ;; + esac else HAVE_LOGF=0 - LOGF_LIBM="$LOG_LIBM" + fi + if test $HAVE_LOGF = 0 || test $REPLACE_LOGF = 1; then + dnl Find libraries needed to link lib/logf.c. + if test $HAVE_LOGF = 0; then + LOGF_LIBM="$LOG_LIBM" + fi fi AC_SUBST([LOGF_LIBM]) ]) + +dnl Test whether logf() works. +dnl On OSF/1 5.1, logf(-0.0f) is NaN. +AC_DEFUN([gl_FUNC_LOGF_WORKS], +[ + AC_REQUIRE([AC_PROG_CC]) + AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles + AC_CACHE_CHECK([whether logf works], [gl_cv_func_logf_works], + [ + AC_RUN_IFELSE( + [AC_LANG_SOURCE([[ +#include +volatile float x; +float y; +int main () +{ + x = -0.0f; + y = logf (x); + if (!(y + y == y)) + return 1; + return 0; +} +]])], + [gl_cv_func_logf_works=yes], + [gl_cv_func_logf_works=no], + [case "$host_os" in + osf*) gl_cv_func_logf_works="guessing no";; + *) gl_cv_func_logf_works="guessing yes";; + esac + ]) + ]) +]) diff --git a/m4/math_h.m4 b/m4/math_h.m4 --- a/m4/math_h.m4 +++ b/m4/math_h.m4 @@ -1,4 +1,4 @@ -# math_h.m4 serial 93 +# math_h.m4 serial 94 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, @@ -261,6 +261,7 @@ REPLACE_ISNAN=0; AC_SUBST([REPLACE_ISNAN]) REPLACE_LDEXPL=0; AC_SUBST([REPLACE_LDEXPL]) REPLACE_LOG=0; AC_SUBST([REPLACE_LOG]) + REPLACE_LOGF=0; AC_SUBST([REPLACE_LOGF]) REPLACE_MODF=0; AC_SUBST([REPLACE_MODF]) REPLACE_MODFF=0; AC_SUBST([REPLACE_MODFF]) REPLACE_MODFL=0; AC_SUBST([REPLACE_MODFL]) diff --git a/modules/logf b/modules/logf --- a/modules/logf +++ b/modules/logf @@ -8,11 +8,11 @@ Depends-on: math extensions -log [test $HAVE_LOGF = 0] +log [test $HAVE_LOGF = 0 || test $REPLACE_LOGF = 1] configure.ac: gl_FUNC_LOGF -if test $HAVE_LOGF = 0; then +if test $HAVE_LOGF = 0 || test $REPLACE_LOGF = 1; then AC_LIBOBJ([logf]) fi gl_MATH_MODULE_INDICATOR([logf]) diff --git a/modules/math b/modules/math --- a/modules/math +++ b/modules/math @@ -230,6 +230,7 @@ -e 's|@''REPLACE_ITOLD''@|$(REPLACE_ITOLD)|g' \ -e 's|@''REPLACE_LDEXPL''@|$(REPLACE_LDEXPL)|g' \ -e 's|@''REPLACE_LOG''@|$(REPLACE_LOG)|g' \ + -e 's|@''REPLACE_LOGF''@|$(REPLACE_LOGF)|g' \ -e 's|@''REPLACE_MODF''@|$(REPLACE_MODF)|g' \ -e 's|@''REPLACE_MODFF''@|$(REPLACE_MODFF)|g' \ -e 's|@''REPLACE_MODFL''@|$(REPLACE_MODFL)|g' \