Mercurial > hg > octave-kai > gnulib-hg
changeset 16737:6828b991e3b9
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
workaround.
* m4/log10f.m4 (gl_FUNC_LOG10F_WORKS): New macro.
(gl_FUNC_LOG10F): Invoke it. Set REPLACE_LOG10F.
* m4/math_h.m4 (gl_MATH_H_DEFAULTS): Initialize REPLACE_LOG10F.
* modules/math (Makefile.am): Substitute REPLACE_LOG10F.
* modules/log10f (configure.ac): Consider REPLACE_LOG10F.
(Depends-on): Update conditions.
* doc/posix-functions/log10f.texi: Mention the OSF/1 5.1 problem.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Sun, 01 Apr 2012 14:29:37 +0200 |
parents | 747e0285fa98 |
children | 25dda52366fd |
files | ChangeLog doc/posix-functions/log10f.texi lib/log10f.c lib/math.in.h m4/log10f.m4 m4/math_h.m4 modules/log10f modules/math |
diffstat | 8 files changed, 91 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2012-04-01 Bruno Haible <bruno@clisp.org> + + 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 + workaround. + * m4/log10f.m4 (gl_FUNC_LOG10F_WORKS): New macro. + (gl_FUNC_LOG10F): Invoke it. Set REPLACE_LOG10F. + * m4/math_h.m4 (gl_MATH_H_DEFAULTS): Initialize REPLACE_LOG10F. + * modules/math (Makefile.am): Substitute REPLACE_LOG10F. + * modules/log10f (configure.ac): Consider REPLACE_LOG10F. + (Depends-on): Update conditions. + * doc/posix-functions/log10f.texi: Mention the OSF/1 5.1 problem. + 2012-04-01 Bruno Haible <bruno@clisp.org> log10: Work around OSF/1 5.1 bug.
--- a/doc/posix-functions/log10f.texi +++ b/doc/posix-functions/log10f.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:
--- a/lib/log10f.c +++ b/lib/log10f.c @@ -21,6 +21,15 @@ float log10f (float x) +#undef log10f { +#if HAVE_LOG10F + /* Work around the OSF/1 5.1 bug. */ + if (x == 0.0f) + /* Return -Infinity. */ + return -1.0f / 0.0f; + return log10f (x); +#else return (float) log10 ((double) x); +#endif }
--- a/lib/math.in.h +++ b/lib/math.in.h @@ -1191,11 +1191,20 @@ #if @GNULIB_LOG10F@ -# if !@HAVE_LOG10F@ -# undef log10f +# if @REPLACE_LOG10F@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef log10f +# define log10f rpl_log10f +# endif +_GL_FUNCDECL_RPL (log10f, float, (float x)); +_GL_CXXALIAS_RPL (log10f, float, (float x)); +# else +# if !@HAVE_LOG10F@ +# undef log10f _GL_FUNCDECL_SYS (log10f, float, (float x)); +# endif +_GL_CXXALIAS_SYS (log10f, float, (float x)); # endif -_GL_CXXALIAS_SYS (log10f, float, (float x)); _GL_CXXALIASWARN (log10f); #elif defined GNULIB_POSIXCHECK # undef log10f
--- a/m4/log10f.m4 +++ b/m4/log10f.m4 @@ -1,4 +1,4 @@ -# log10f.m4 serial 2 +# log10f.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,55 @@ LIBS="$save_LIBS" if test $ac_cv_func_log10f = yes; then LOG10F_LIBM="$LOG10_LIBM" + + save_LIBS="$LIBS" + LIBS="$LIBS $LOG10F_LIBM" + gl_FUNC_LOG10F_WORKS + LIBS="$save_LIBS" + case "$gl_cv_func_log10f_works" in + *yes) ;; + *) REPLACE_LOG10F=1 ;; + esac else HAVE_LOG10F=0 - LOG10F_LIBM="$LOG10_LIBM" + fi + if test $HAVE_LOG10F = 0 || test $REPLACE_LOG10F = 1; then + dnl Find libraries needed to link lib/log10f.c. + if test $HAVE_LOG10F = 0; then + LOG10F_LIBM="$LOG10_LIBM" + fi fi AC_SUBST([LOG10F_LIBM]) ]) + +dnl Test whether log10f() works. +dnl On OSF/1 5.1, log10f(-0.0f) is NaN. +AC_DEFUN([gl_FUNC_LOG10F_WORKS], +[ + AC_REQUIRE([AC_PROG_CC]) + AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles + AC_CACHE_CHECK([whether log10f works], [gl_cv_func_log10f_works], + [ + AC_RUN_IFELSE( + [AC_LANG_SOURCE([[ +#include <math.h> +volatile float x; +float y; +int main () +{ + x = -0.0f; + y = log10f (x); + if (!(y + y == y)) + return 1; + return 0; +} +]])], + [gl_cv_func_log10f_works=yes], + [gl_cv_func_log10f_works=no], + [case "$host_os" in + osf*) gl_cv_func_log10f_works="guessing no";; + *) gl_cv_func_log10f_works="guessing yes";; + esac + ]) + ]) +])
--- a/m4/math_h.m4 +++ b/m4/math_h.m4 @@ -1,4 +1,4 @@ -# math_h.m4 serial 105 +# math_h.m4 serial 106 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, @@ -279,6 +279,7 @@ REPLACE_LOGF=0; AC_SUBST([REPLACE_LOGF]) REPLACE_LOGL=0; AC_SUBST([REPLACE_LOGL]) REPLACE_LOG10=0; AC_SUBST([REPLACE_LOG10]) + REPLACE_LOG10F=0; AC_SUBST([REPLACE_LOG10F]) REPLACE_LOG1P=0; AC_SUBST([REPLACE_LOG1P]) REPLACE_LOG1PF=0; AC_SUBST([REPLACE_LOG1PF]) REPLACE_LOG1PL=0; AC_SUBST([REPLACE_LOG1PL])
--- a/modules/log10f +++ b/modules/log10f @@ -8,11 +8,11 @@ Depends-on: math extensions -log10 [test $HAVE_LOG10F = 0] +log10 [test $HAVE_LOG10F = 0 || test $REPLACE_LOG10F = 1] configure.ac: gl_FUNC_LOG10F -if test $HAVE_LOG10F = 0; then +if test $HAVE_LOG10F = 0 || test $REPLACE_LOG10F = 1; then AC_LIBOBJ([log10f]) fi gl_MATH_MODULE_INDICATOR([log10f])
--- a/modules/math +++ b/modules/math @@ -246,6 +246,7 @@ -e 's|@''REPLACE_LOGF''@|$(REPLACE_LOGF)|g' \ -e 's|@''REPLACE_LOGL''@|$(REPLACE_LOGL)|g' \ -e 's|@''REPLACE_LOG10''@|$(REPLACE_LOG10)|g' \ + -e 's|@''REPLACE_LOG10F''@|$(REPLACE_LOG10F)|g' \ -e 's|@''REPLACE_LOG1P''@|$(REPLACE_LOG1P)|g' \ -e 's|@''REPLACE_LOG1PF''@|$(REPLACE_LOG1PF)|g' \ -e 's|@''REPLACE_LOG1PL''@|$(REPLACE_LOG1PL)|g' \