From: Bruno Haible Date: Sun, 1 Apr 2012 12:29:37 +0000 (+0200) Subject: log10f: Work around OSF/1 5.1 bug. X-Git-Tag: v0.1~789 X-Git-Url: http://erislabs.org.uk/gitweb/?a=commitdiff_plain;h=ac05a13b444792260deaadfeb15f5c137ba9072b;p=gnulib.git 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. --- diff --git a/ChangeLog b/ChangeLog index 67191809f..06eb7fb59 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,19 @@ 2012-04-01 Bruno Haible + 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 + log10: Work around OSF/1 5.1 bug. * lib/math.in.h (log10): New declaration. * lib/log10.c: New file. diff --git a/doc/posix-functions/log10f.texi b/doc/posix-functions/log10f.texi index f63509bd4..9eac2ce03 100644 --- a/doc/posix-functions/log10f.texi +++ b/doc/posix-functions/log10f.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/log10f.c b/lib/log10f.c index 3171114b1..bc46e5f8d 100644 --- 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 } diff --git a/lib/math.in.h b/lib/math.in.h index 3a77922d3..335238df5 100644 --- a/lib/math.in.h +++ b/lib/math.in.h @@ -1191,11 +1191,20 @@ _GL_WARN_ON_USE (logl, "logl is unportable - " #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 +# endif _GL_CXXALIAS_SYS (log10f, float, (float x)); +# endif _GL_CXXALIASWARN (log10f); #elif defined GNULIB_POSIXCHECK # undef log10f diff --git a/m4/log10f.m4 b/m4/log10f.m4 index e9f8ce1a5..510a47adc 100644 --- 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 @@ AC_DEFUN([gl_FUNC_LOG10F], 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 +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 + ]) + ]) +]) diff --git a/m4/math_h.m4 b/m4/math_h.m4 index 2fe2ecef6..5bfa28c5d 100644 --- 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 @@ AC_DEFUN([gl_MATH_H_DEFAULTS], 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]) diff --git a/modules/log10f b/modules/log10f index abcbaa64a..5826be9f0 100644 --- a/modules/log10f +++ b/modules/log10f @@ -8,11 +8,11 @@ m4/log10f.m4 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]) diff --git a/modules/math b/modules/math index ceb77884a..cb81a7dd4 100644 --- a/modules/math +++ b/modules/math @@ -246,6 +246,7 @@ math.h: math.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $( -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' \