Mercurial > hg > octave-lyh > gnulib-hg
changeset 16631:45443deebb7d
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.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Fri, 09 Mar 2012 23:55:13 +0100 |
parents | 1ac24dbbff5a |
children | 2450f24b2cbc |
files | ChangeLog doc/posix-functions/log.texi lib/log.c lib/math.in.h m4/log.m4 m4/math_h.m4 modules/log modules/math tests/test-math-c++.cc |
diffstat | 9 files changed, 127 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,19 @@ +2012-03-09 Bruno Haible <bruno@clisp.org> + + 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 <meyering@redhat.com> readtokens.c: adjust wording in a comment
--- a/doc/posix-functions/log.texi +++ b/doc/posix-functions/log.texi @@ -8,6 +8,9 @@ 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:
new file mode 100644 --- /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 <http://www.gnu.org/licenses/>. */ + +#include <config.h> + +/* Specification. */ +#include <math.h> + +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); +}
--- a/lib/math.in.h +++ b/lib/math.in.h @@ -1136,6 +1136,26 @@ # 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
--- 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 @@ [ 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 <math.h> +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 + ]) + ]) +])
--- 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 @@ 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 @@ 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 @@ 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])
--- a/modules/log +++ b/modules/log @@ -2,13 +2,19 @@ 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:
--- a/modules/math +++ b/modules/math @@ -81,6 +81,7 @@ -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 @@ -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' \
--- a/tests/test-math-c++.cc +++ b/tests/test-math-c++.cc @@ -222,7 +222,9 @@ #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