logf: Work around OSF/1 5.1 bug.
authorBruno Haible <bruno@clisp.org>
Fri, 9 Mar 2012 23:55:48 +0000 (00:55 +0100)
committerBruno Haible <bruno@clisp.org>
Sat, 10 Mar 2012 09:37:41 +0000 (10:37 +0100)
* lib/math.in.h (logf): Override if REPLACE_LOGF is 1.
* lib/logf.c (logf): If logf exists, use it and provide just the
workaround.
* m4/logf.m4 (gl_FUNC_LOGF_WORKS): New macro.
(gl_FUNC_LOGF): Invoke it. Set REPLACE_LOGF.
* m4/math_h.m4 (gl_MATH_H_DEFAULTS): Initialize REPLACE_LOGF.
* modules/math (Makefile.am): Substitute REPLACE_LOGF.
* modules/logf (configure.ac): Consider REPLACE_LOGF.
(Depends-on): Update conditions.
* doc/posix-functions/logf.texi: Mention the OSF/1 5.1 problem.

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

index ef58c93..4340257 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,19 @@
 2012-03-09  Bruno Haible  <bruno@clisp.org>
 
+       logf: Work around OSF/1 5.1 bug.
+       * lib/math.in.h (logf): Override if REPLACE_LOGF is 1.
+       * lib/logf.c (logf): If logf exists, use it and provide just the
+       workaround.
+       * m4/logf.m4 (gl_FUNC_LOGF_WORKS): New macro.
+       (gl_FUNC_LOGF): Invoke it. Set REPLACE_LOGF.
+       * m4/math_h.m4 (gl_MATH_H_DEFAULTS): Initialize REPLACE_LOGF.
+       * modules/math (Makefile.am): Substitute REPLACE_LOGF.
+       * modules/logf (configure.ac): Consider REPLACE_LOGF.
+       (Depends-on): Update conditions.
+       * doc/posix-functions/logf.texi: Mention the OSF/1 5.1 problem.
+
+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.
index a4de780..21b5f74 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 51696e5..3bf0f13 100644 (file)
 
 float
 logf (float x)
+#undef logf
 {
+#if HAVE_LOGF
+  /* Work around the OSF/1 5.1 bug.  */
+  if (x == 0.0f)
+    /* Return -Infinity.  */
+    return -1.0f / 0.0f;
+  return logf (x);
+#else
   return (float) log ((double) x);
+#endif
 }
index b718ecf..daf7a82 100644 (file)
@@ -1122,11 +1122,20 @@ _GL_WARN_ON_USE (logb, "logb is unportable - "
 
 
 #if @GNULIB_LOGF@
-# if !@HAVE_LOGF@
-#  undef logf
+# if @REPLACE_LOGF@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef logf
+#   define logf rpl_logf
+#  endif
+_GL_FUNCDECL_RPL (logf, float, (float x));
+_GL_CXXALIAS_RPL (logf, float, (float x));
+# else
+#  if !@HAVE_LOGF@
+#   undef logf
 _GL_FUNCDECL_SYS (logf, float, (float x));
-# endif
+#  endif
 _GL_CXXALIAS_SYS (logf, float, (float x));
+# endif
 _GL_CXXALIASWARN (logf);
 #elif defined GNULIB_POSIXCHECK
 # undef logf
index 717ccee..0e4fa5d 100644 (file)
@@ -1,4 +1,4 @@
-# logf.m4 serial 2
+# logf.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,54 @@ AC_DEFUN([gl_FUNC_LOGF],
   LIBS="$save_LIBS"
   if test $ac_cv_func_logf = yes; then
     LOGF_LIBM="$LOG_LIBM"
+    save_LIBS="$LIBS"
+    LIBS="$LIBS $LOGF_LIBM"
+    gl_FUNC_LOGF_WORKS
+    LIBS="$save_LIBS"
+    case "$gl_cv_func_logf_works" in
+      *yes) ;;
+      *) REPLACE_LOGF=1 ;;
+    esac
   else
     HAVE_LOGF=0
-    LOGF_LIBM="$LOG_LIBM"
+  fi
+  if test $HAVE_LOGF = 0 || test $REPLACE_LOGF = 1; then
+    dnl Find libraries needed to link lib/logf.c.
+    if test $HAVE_LOGF = 0; then
+      LOGF_LIBM="$LOG_LIBM"
+    fi
   fi
   AC_SUBST([LOGF_LIBM])
 ])
+
+dnl Test whether logf() works.
+dnl On OSF/1 5.1, logf(-0.0f) is NaN.
+AC_DEFUN([gl_FUNC_LOGF_WORKS],
+[
+  AC_REQUIRE([AC_PROG_CC])
+  AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
+  AC_CACHE_CHECK([whether logf works], [gl_cv_func_logf_works],
+    [
+      AC_RUN_IFELSE(
+        [AC_LANG_SOURCE([[
+#include <math.h>
+volatile float x;
+float y;
+int main ()
+{
+  x = -0.0f;
+  y = logf (x);
+  if (!(y + y == y))
+    return 1;
+  return 0;
+}
+]])],
+        [gl_cv_func_logf_works=yes],
+        [gl_cv_func_logf_works=no],
+        [case "$host_os" in
+           osf*) gl_cv_func_logf_works="guessing no";;
+           *)    gl_cv_func_logf_works="guessing yes";;
+         esac
+        ])
+    ])
+])
index 8c46e0c..8d9d907 100644 (file)
@@ -1,4 +1,4 @@
-# math_h.m4 serial 93
+# math_h.m4 serial 94
 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,
@@ -261,6 +261,7 @@ AC_DEFUN([gl_MATH_H_DEFAULTS],
   REPLACE_ISNAN=0;             AC_SUBST([REPLACE_ISNAN])
   REPLACE_LDEXPL=0;            AC_SUBST([REPLACE_LDEXPL])
   REPLACE_LOG=0;               AC_SUBST([REPLACE_LOG])
+  REPLACE_LOGF=0;              AC_SUBST([REPLACE_LOGF])
   REPLACE_MODF=0;              AC_SUBST([REPLACE_MODF])
   REPLACE_MODFF=0;             AC_SUBST([REPLACE_MODFF])
   REPLACE_MODFL=0;             AC_SUBST([REPLACE_MODFL])
index 7811af2..d4657a5 100644 (file)
@@ -8,11 +8,11 @@ m4/logf.m4
 Depends-on:
 math
 extensions
-log             [test $HAVE_LOGF = 0]
+log             [test $HAVE_LOGF = 0 || test $REPLACE_LOGF = 1]
 
 configure.ac:
 gl_FUNC_LOGF
-if test $HAVE_LOGF = 0; then
+if test $HAVE_LOGF = 0 || test $REPLACE_LOGF = 1; then
   AC_LIBOBJ([logf])
 fi
 gl_MATH_MODULE_INDICATOR([logf])
index cc68724..9419a87 100644 (file)
@@ -230,6 +230,7 @@ math.h: math.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(
              -e 's|@''REPLACE_ITOLD''@|$(REPLACE_ITOLD)|g' \
              -e 's|@''REPLACE_LDEXPL''@|$(REPLACE_LDEXPL)|g' \
              -e 's|@''REPLACE_LOG''@|$(REPLACE_LOG)|g' \
+             -e 's|@''REPLACE_LOGF''@|$(REPLACE_LOGF)|g' \
              -e 's|@''REPLACE_MODF''@|$(REPLACE_MODF)|g' \
              -e 's|@''REPLACE_MODFF''@|$(REPLACE_MODFF)|g' \
              -e 's|@''REPLACE_MODFL''@|$(REPLACE_MODFL)|g' \