log10f: Work around OSF/1 5.1 bug.
authorBruno Haible <bruno@clisp.org>
Sun, 1 Apr 2012 12:29:37 +0000 (14:29 +0200)
committerBruno Haible <bruno@clisp.org>
Sun, 1 Apr 2012 14:37:09 +0000 (16:37 +0200)
* 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.

ChangeLog
doc/posix-functions/log10f.texi
lib/log10f.c
lib/math.in.h
m4/log10f.m4
m4/math_h.m4
modules/log10f
modules/math

index 6719180..06eb7fb 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,19 @@
 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.
        * lib/math.in.h (log10): New declaration.
        * lib/log10.c: New file.
index f63509b..9eac2ce 100644 (file)
@@ -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:
index 3171114..bc46e5f 100644 (file)
 
 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
 }
index 3a77922..335238d 100644 (file)
@@ -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
index e9f8ce1..510a47a 100644 (file)
@@ -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 <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
+        ])
+    ])
+])
index 2fe2ece..5bfa28c 100644 (file)
@@ -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])
index abcbaa6..5826be9 100644 (file)
@@ -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])
index ceb7788..cb81a7d 100644 (file)
@@ -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' \