From 7073cb033569232bd515271e99c5c7cba4ffbdf5 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sat, 10 Mar 2012 00:55:48 +0100 Subject: [PATCH] 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. --- ChangeLog | 14 +++++++++++++ doc/posix-functions/logf.texi | 3 +++ lib/logf.c | 9 ++++++++ lib/math.in.h | 15 ++++++++++--- m4/logf.m4 | 49 +++++++++++++++++++++++++++++++++++++++++-- m4/math_h.m4 | 3 ++- modules/logf | 4 ++-- modules/math | 1 + 8 files changed, 90 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index ef58c9312..43402579e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,19 @@ 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. * lib/math.in.h (log): New declaration. * lib/log.c: New file. diff --git a/doc/posix-functions/logf.texi b/doc/posix-functions/logf.texi index a4de780b7..21b5f7465 100644 --- a/doc/posix-functions/logf.texi +++ b/doc/posix-functions/logf.texi @@ -14,6 +14,9 @@ Minix 3.1.8, AIX 5.1, Solaris 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 index 51696e531..3bf0f138f 100644 --- 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 index b718ecf4b..daf7a8229 100644 --- a/lib/math.in.h +++ b/lib/math.in.h @@ -1122,11 +1122,20 @@ _GL_WARN_ON_USE (logb, "logb is unportable - " #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 +# endif _GL_CXXALIAS_SYS (logf, float, (float x)); +# endif _GL_CXXALIASWARN (logf); #elif defined GNULIB_POSIXCHECK # undef logf diff --git a/m4/logf.m4 b/m4/logf.m4 index 717ccee6d..0e4fa5da6 100644 --- 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 @@ AC_DEFUN([gl_FUNC_LOGF], 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 index 8c46e0cbf..8d9d9075c 100644 --- 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 @@ AC_DEFUN([gl_MATH_H_DEFAULTS], 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 index 7811af22f..d4657a5cd 100644 --- a/modules/logf +++ b/modules/logf @@ -8,11 +8,11 @@ m4/logf.m4 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 index cc68724e3..9419a875a 100644 --- a/modules/math +++ b/modules/math @@ -230,6 +230,7 @@ math.h: math.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $( -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' \ -- 2.11.0