From: Bruno Haible Date: Fri, 9 Mar 2012 22:55:13 +0000 (+0100) Subject: log: Work around OSF/1 5.1 bug. X-Git-Tag: v0.1~895 X-Git-Url: http://erislabs.net/gitweb/?p=gnulib.git;a=commitdiff_plain;h=0d37a2e60081400c4ecefbb106e8a1749b3de2b0 log: Work around OSF/1 5.1 bug. * lib/math.in.h (log): New declaration. * lib/log.c: New file. * m4/log.m4 (gl_FUNC_LOG_WORKS): New macro. (gl_FUNC_LOG): Invoke it. Set REPLACE_LOG. * m4/math_h.m4 (gl_MATH_H): Test whether log is declared. (gl_MATH_H_DEFAULTS): Initialize GNULIB_LOG, REPLACE_LOG. * modules/math (Makefile.am): Substitute GNULIB_LOG, REPLACE_LOG. * modules/log (Files): Add lib/log.c. (Depends-on): Add math. (configure.ac): If REPLACE_LOG is 1, compile an override. * tests/test-math-c++.cc: Check the declaration of log. * doc/posix-functions/log.texi: Mention the OSF/1 5.1 problem. --- diff --git a/ChangeLog b/ChangeLog index 1829df045..ef58c9312 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,19 @@ +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. + * m4/log.m4 (gl_FUNC_LOG_WORKS): New macro. + (gl_FUNC_LOG): Invoke it. Set REPLACE_LOG. + * m4/math_h.m4 (gl_MATH_H): Test whether log is declared. + (gl_MATH_H_DEFAULTS): Initialize GNULIB_LOG, REPLACE_LOG. + * modules/math (Makefile.am): Substitute GNULIB_LOG, REPLACE_LOG. + * modules/log (Files): Add lib/log.c. + (Depends-on): Add math. + (configure.ac): If REPLACE_LOG is 1, compile an override. + * tests/test-math-c++.cc: Check the declaration of log. + * doc/posix-functions/log.texi: Mention the OSF/1 5.1 problem. + 2012-03-09 Jim Meyering readtokens.c: adjust wording in a comment diff --git a/doc/posix-functions/log.texi b/doc/posix-functions/log.texi index 0f79f8bb1..2e67cedbc 100644 --- a/doc/posix-functions/log.texi +++ b/doc/posix-functions/log.texi @@ -8,6 +8,9 @@ Gnulib module: log Portability problems fixed by Gnulib: @itemize +@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/log.c b/lib/log.c new file mode 100644 index 000000000..960ec82b5 --- /dev/null +++ b/lib/log.c @@ -0,0 +1,31 @@ +/* Logarithm. + Copyright (C) 2012 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#include + +/* Specification. */ +#include + +double +log (double x) +#undef log +{ + /* Work around the OSF/1 5.1 bug. */ + if (x == 0.0) + /* Return -Infinity. */ + return -1.0 / 0.0; + return log (x); +} diff --git a/lib/math.in.h b/lib/math.in.h index 2dba028e7..b718ecf4b 100644 --- a/lib/math.in.h +++ b/lib/math.in.h @@ -1136,6 +1136,26 @@ _GL_WARN_ON_USE (logf, "logf is unportable - " # endif #endif +#if @GNULIB_LOG@ +# if @REPLACE_LOG@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef log +# define log rpl_log +# endif +_GL_FUNCDECL_RPL (log, double, (double x)); +_GL_CXXALIAS_RPL (log, double, (double x)); +# else +_GL_CXXALIAS_SYS (log, double, (double x)); +# endif +_GL_CXXALIASWARN (log); +#elif defined GNULIB_POSIXCHECK +# undef log +# if HAVE_RAW_DECL_LOG +_GL_WARN_ON_USE (log, "log has portability problems - " + "use gnulib module log for portability"); +# endif +#endif + #if @GNULIB_LOGL@ # if !@HAVE_LOGL@ || !@HAVE_DECL_LOGL@ # undef logl diff --git a/m4/log.m4 b/m4/log.m4 index 35a2cb453..bc1c378eb 100644 --- a/m4/log.m4 +++ b/m4/log.m4 @@ -1,4 +1,4 @@ -# log.m4 serial 1 +# log.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, @@ -8,4 +8,45 @@ AC_DEFUN([gl_FUNC_LOG], [ dnl Determine LOG_LIBM. gl_COMMON_DOUBLE_MATHFUNC([log]) + + save_LIBS="$LIBS" + LIBS="$LIBS $LOG_LIBM" + gl_FUNC_LOG_WORKS + LIBS="$save_LIBS" + case "$gl_cv_func_log_works" in + *yes) ;; + *) REPLACE_LOG=1 ;; + esac +]) + +dnl Test whether log() works. +dnl On OSF/1 5.1, log(-0.0) is NaN. +AC_DEFUN([gl_FUNC_LOG_WORKS], +[ + AC_REQUIRE([AC_PROG_CC]) + AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles + AC_CACHE_CHECK([whether log works], [gl_cv_func_log_works], + [ + AC_RUN_IFELSE( + [AC_LANG_SOURCE([[ +#include +volatile double x; +double y; +int main () +{ + x = -0.0; + y = log (x); + if (!(y + y == y)) + return 1; + return 0; +} +]])], + [gl_cv_func_log_works=yes], + [gl_cv_func_log_works=no], + [case "$host_os" in + osf*) gl_cv_func_log_works="guessing no";; + *) gl_cv_func_log_works="guessing yes";; + esac + ]) + ]) ]) diff --git a/m4/math_h.m4 b/m4/math_h.m4 index 953ad1938..8c46e0cbf 100644 --- a/m4/math_h.m4 +++ b/m4/math_h.m4 @@ -1,4 +1,4 @@ -# math_h.m4 serial 92 +# math_h.m4 serial 93 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, @@ -44,7 +44,7 @@ AC_DEFUN([gl_MATH_H], expf expl exp2 exp2f exp2l expm1 expm1f expm1l fabsf fabsl floorf floorl fma fmaf fmal fmod fmodf fmodl frexpf frexpl hypotf hypotl - ldexpf ldexpl logb logf logl log10f log10l modf modff modfl powf + ldexpf ldexpl logb log logf logl log10f log10l modf modff modfl powf remainder remainderf remainderl rint rintf rintl round roundf roundl sinf sinl sinhf sqrtf sqrtl tanf tanl tanhf trunc truncf truncl]) @@ -114,6 +114,7 @@ AC_DEFUN([gl_MATH_H_DEFAULTS], GNULIB_LDEXPF=0; AC_SUBST([GNULIB_LDEXPF]) GNULIB_LDEXPL=0; AC_SUBST([GNULIB_LDEXPL]) GNULIB_LOGB=0; AC_SUBST([GNULIB_LOGB]) + GNULIB_LOG=0; AC_SUBST([GNULIB_LOG]) GNULIB_LOGF=0; AC_SUBST([GNULIB_LOGF]) GNULIB_LOGL=0; AC_SUBST([GNULIB_LOGL]) GNULIB_LOG10F=0; AC_SUBST([GNULIB_LOG10F]) @@ -259,6 +260,7 @@ AC_DEFUN([gl_MATH_H_DEFAULTS], REPLACE_ISINF=0; AC_SUBST([REPLACE_ISINF]) REPLACE_ISNAN=0; AC_SUBST([REPLACE_ISNAN]) REPLACE_LDEXPL=0; AC_SUBST([REPLACE_LDEXPL]) + REPLACE_LOG=0; AC_SUBST([REPLACE_LOG]) 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/log b/modules/log index 9f320a37b..824f8c9d7 100644 --- a/modules/log +++ b/modules/log @@ -2,13 +2,19 @@ Description: log() function: natural logarithmic function. Files: +lib/log.c m4/log.m4 m4/mathfunc.m4 Depends-on: +math configure.ac: gl_FUNC_LOG +if test $REPLACE_LOG = 1; then + AC_LIBOBJ([log]) +fi +gl_MATH_MODULE_INDICATOR([log]) Makefile.am: diff --git a/modules/math b/modules/math index 74671719e..cc68724e3 100644 --- a/modules/math +++ b/modules/math @@ -81,6 +81,7 @@ math.h: math.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $( -e 's/@''GNULIB_LDEXPF''@/$(GNULIB_LDEXPF)/g' \ -e 's/@''GNULIB_LDEXPL''@/$(GNULIB_LDEXPL)/g' \ -e 's/@''GNULIB_LOGB''@/$(GNULIB_LOGB)/g' \ + -e 's/@''GNULIB_LOG''@/$(GNULIB_LOG)/g' \ -e 's/@''GNULIB_LOGF''@/$(GNULIB_LOGF)/g' \ -e 's/@''GNULIB_LOGL''@/$(GNULIB_LOGL)/g' \ -e 's/@''GNULIB_LOG10F''@/$(GNULIB_LOG10F)/g' \ @@ -228,6 +229,7 @@ math.h: math.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $( -e 's|@''REPLACE_ISNAN''@|$(REPLACE_ISNAN)|g' \ -e 's|@''REPLACE_ITOLD''@|$(REPLACE_ITOLD)|g' \ -e 's|@''REPLACE_LDEXPL''@|$(REPLACE_LDEXPL)|g' \ + -e 's|@''REPLACE_LOG''@|$(REPLACE_LOG)|g' \ -e 's|@''REPLACE_MODF''@|$(REPLACE_MODF)|g' \ -e 's|@''REPLACE_MODFF''@|$(REPLACE_MODFF)|g' \ -e 's|@''REPLACE_MODFL''@|$(REPLACE_MODFL)|g' \ diff --git a/tests/test-math-c++.cc b/tests/test-math-c++.cc index ed061d86f..a5619b29a 100644 --- a/tests/test-math-c++.cc +++ b/tests/test-math-c++.cc @@ -222,7 +222,9 @@ SIGNATURE_CHECK (GNULIB_NAMESPACE::log10l, long double, (long double)); #if GNULIB_TEST_LOGF SIGNATURE_CHECK (GNULIB_NAMESPACE::logf, float, (float)); #endif -//SIGNATURE_CHECK (GNULIB_NAMESPACE::log, double, (double)); +#if GNULIB_TEST_LOG +SIGNATURE_CHECK (GNULIB_NAMESPACE::log, double, (double)); +#endif #if GNULIB_TEST_LOGL SIGNATURE_CHECK (GNULIB_NAMESPACE::logl, long double, (long double)); #endif