log10: Work around OSF/1 5.1 bug.
authorBruno Haible <bruno@clisp.org>
Sun, 1 Apr 2012 11:19:41 +0000 (13:19 +0200)
committerBruno Haible <bruno@clisp.org>
Sun, 1 Apr 2012 14:37:08 +0000 (16:37 +0200)
* lib/math.in.h (log10): New declaration.
* lib/log10.c: New file.
* m4/log10.m4 (gl_FUNC_LOG10_WORKS): New macro.
(gl_FUNC_LOG10): Invoke it. Set REPLACE_LOG10.
* m4/math_h.m4 (gl_MATH_H): Test whether log10 is declared.
(gl_MATH_H_DEFAULTS): Initialize GNULIB_LOG10, REPLACE_LOG10.
* modules/math (Makefile.am): Substitute GNULIB_LOG10, REPLACE_LOG10.
* modules/log10 (Files): Add lib/log10.c.
(Depends-on): Add math.
(configure.ac): If REPLACE_LOG10 is 1, compile an override.
* tests/test-math-c++.cc: Check the declaration of log10.
* doc/posix-functions/log10.texi: Mention the OSF/1 5.1 problem.

ChangeLog
doc/posix-functions/log10.texi
lib/log10.c [new file with mode: 0644]
lib/math.in.h
m4/log10.m4
m4/math_h.m4
modules/log10
modules/math
tests/test-math-c++.cc

index 45c4197..6719180 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+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.
+       * m4/log10.m4 (gl_FUNC_LOG10_WORKS): New macro.
+       (gl_FUNC_LOG10): Invoke it. Set REPLACE_LOG10.
+       * m4/math_h.m4 (gl_MATH_H): Test whether log10 is declared.
+       (gl_MATH_H_DEFAULTS): Initialize GNULIB_LOG10, REPLACE_LOG10.
+       * modules/math (Makefile.am): Substitute GNULIB_LOG10, REPLACE_LOG10.
+       * modules/log10 (Files): Add lib/log10.c.
+       (Depends-on): Add math.
+       (configure.ac): If REPLACE_LOG10 is 1, compile an override.
+       * tests/test-math-c++.cc: Check the declaration of log10.
+       * doc/posix-functions/log10.texi: Mention the OSF/1 5.1 problem.
+
 2012-03-31  Bruno Haible  <bruno@clisp.org>
 
        log10l tests: More tests.
index 0674fdb..34936d1 100644 (file)
@@ -8,6 +8,9 @@ Gnulib module: log10
 
 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:
diff --git a/lib/log10.c b/lib/log10.c
new file mode 100644 (file)
index 0000000..9e959b8
--- /dev/null
@@ -0,0 +1,31 @@
+/* Base 10 logarithmic function.
+   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
+log10 (double x)
+#undef log10
+{
+  /* Work around the OSF/1 5.1 bug.  */
+  if (x == 0.0)
+    /* Return -Infinity.  */
+    return -1.0 / 0.0;
+  return log10 (x);
+}
index 4b2ce87..3a77922 100644 (file)
@@ -1205,6 +1205,26 @@ _GL_WARN_ON_USE (log10f, "log10f is unportable - "
 # endif
 #endif
 
+#if @GNULIB_LOG10@
+# if @REPLACE_LOG10@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef log10
+#   define log10 rpl_log10
+#  endif
+_GL_FUNCDECL_RPL (log10, double, (double x));
+_GL_CXXALIAS_RPL (log10, double, (double x));
+# else
+_GL_CXXALIAS_SYS (log10, double, (double x));
+# endif
+_GL_CXXALIASWARN (log10);
+#elif defined GNULIB_POSIXCHECK
+# undef log10
+# if HAVE_RAW_DECL_LOG10
+_GL_WARN_ON_USE (log10, "log10 has portability problems - "
+                 "use gnulib module log10 for portability");
+# endif
+#endif
+
 #if @GNULIB_LOG10L@
 # if !@HAVE_LOG10L@ || !@HAVE_DECL_LOG10L@
 #  undef log10l
index 251c1c6..ab066cc 100644 (file)
@@ -1,4 +1,4 @@
-# log10.m4 serial 1
+# log10.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,
@@ -6,6 +6,49 @@ dnl with or without modifications, as long as this notice is preserved.
 
 AC_DEFUN([gl_FUNC_LOG10],
 [
+  AC_REQUIRE([gl_MATH_H_DEFAULTS])
+
   dnl Determine LOG10_LIBM.
   gl_COMMON_DOUBLE_MATHFUNC([log10])
+
+  save_LIBS="$LIBS"
+  LIBS="$LIBS $LOG10_LIBM"
+  gl_FUNC_LOG10_WORKS
+  LIBS="$save_LIBS"
+  case "$gl_cv_func_log10_works" in
+    *yes) ;;
+    *) REPLACE_LOG10=1 ;;
+  esac
+])
+
+dnl Test whether log10() works.
+dnl On OSF/1 5.1, log10(-0.0) is NaN.
+AC_DEFUN([gl_FUNC_LOG10_WORKS],
+[
+  AC_REQUIRE([AC_PROG_CC])
+  AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
+  AC_CACHE_CHECK([whether log10 works], [gl_cv_func_log10_works],
+    [
+      AC_RUN_IFELSE(
+        [AC_LANG_SOURCE([[
+#include <math.h>
+volatile double x;
+double y;
+int main ()
+{
+  x = -0.0;
+  y = log10 (x);
+  if (!(y + y == y))
+    return 1;
+  return 0;
+}
+]])],
+        [gl_cv_func_log10_works=yes],
+        [gl_cv_func_log10_works=no],
+        [case "$host_os" in
+           osf*) gl_cv_func_log10_works="guessing no";;
+           *)    gl_cv_func_log10_works="guessing yes";;
+         esac
+        ])
+    ])
 ])
index ff1654e..2fe2ece 100644 (file)
@@ -1,4 +1,4 @@
-# math_h.m4 serial 104
+# math_h.m4 serial 105
 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,
@@ -45,7 +45,7 @@ AC_DEFUN([gl_MATH_H],
      fabsf fabsl floorf floorl fma fmaf fmal
      fmod fmodf fmodl frexpf frexpl hypotf hypotl
      ldexpf ldexpl
-     logb log logf logl log10f log10l log1p log1pf log1pl log2 log2f log2l
+     logb log logf logl log10 log10f log10l log1p log1pf log1pl log2 log2f log2l
      modf modff modfl powf
      remainder remainderf remainderl
      rint rintf rintl round roundf roundl sinf sinl sinhf sqrtf sqrtl
@@ -119,6 +119,7 @@ AC_DEFUN([gl_MATH_H_DEFAULTS],
   GNULIB_LOG=0;        AC_SUBST([GNULIB_LOG])
   GNULIB_LOGF=0;       AC_SUBST([GNULIB_LOGF])
   GNULIB_LOGL=0;       AC_SUBST([GNULIB_LOGL])
+  GNULIB_LOG10=0;      AC_SUBST([GNULIB_LOG10])
   GNULIB_LOG10F=0;     AC_SUBST([GNULIB_LOG10F])
   GNULIB_LOG10L=0;     AC_SUBST([GNULIB_LOG10L])
   GNULIB_LOG1P=0;      AC_SUBST([GNULIB_LOG1P])
@@ -277,6 +278,7 @@ AC_DEFUN([gl_MATH_H_DEFAULTS],
   REPLACE_LOG=0;               AC_SUBST([REPLACE_LOG])
   REPLACE_LOGF=0;              AC_SUBST([REPLACE_LOGF])
   REPLACE_LOGL=0;              AC_SUBST([REPLACE_LOGL])
+  REPLACE_LOG10=0;             AC_SUBST([REPLACE_LOG10])
   REPLACE_LOG1P=0;             AC_SUBST([REPLACE_LOG1P])
   REPLACE_LOG1PF=0;            AC_SUBST([REPLACE_LOG1PF])
   REPLACE_LOG1PL=0;            AC_SUBST([REPLACE_LOG1PL])
index 4385288..3918d1f 100644 (file)
@@ -2,13 +2,19 @@ Description:
 log10() function: base 10 logarithmic function.
 
 Files:
+lib/log10.c
 m4/log10.m4
 m4/mathfunc.m4
 
 Depends-on:
+math
 
 configure.ac:
 gl_FUNC_LOG10
+if test $REPLACE_LOG10 = 1; then
+  AC_LIBOBJ([log10])
+fi
+gl_MATH_MODULE_INDICATOR([log10])
 
 Makefile.am:
 
index 51db89e..ceb7788 100644 (file)
@@ -84,6 +84,7 @@ math.h: math.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(
              -e 's/@''GNULIB_LOG''@/$(GNULIB_LOG)/g' \
              -e 's/@''GNULIB_LOGF''@/$(GNULIB_LOGF)/g' \
              -e 's/@''GNULIB_LOGL''@/$(GNULIB_LOGL)/g' \
+             -e 's/@''GNULIB_LOG10''@/$(GNULIB_LOG10)/g' \
              -e 's/@''GNULIB_LOG10F''@/$(GNULIB_LOG10F)/g' \
              -e 's/@''GNULIB_LOG10L''@/$(GNULIB_LOG10L)/g' \
              -e 's/@''GNULIB_LOG1P''@/$(GNULIB_LOG1P)/g' \
@@ -244,6 +245,7 @@ math.h: math.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(
              -e 's|@''REPLACE_LOG''@|$(REPLACE_LOG)|g' \
              -e 's|@''REPLACE_LOGF''@|$(REPLACE_LOGF)|g' \
              -e 's|@''REPLACE_LOGL''@|$(REPLACE_LOGL)|g' \
+             -e 's|@''REPLACE_LOG10''@|$(REPLACE_LOG10)|g' \
              -e 's|@''REPLACE_LOG1P''@|$(REPLACE_LOG1P)|g' \
              -e 's|@''REPLACE_LOG1PF''@|$(REPLACE_LOG1PF)|g' \
              -e 's|@''REPLACE_LOG1PL''@|$(REPLACE_LOG1PL)|g' \
index 9caa951..b6df659 100644 (file)
@@ -210,7 +210,9 @@ SIGNATURE_CHECK (GNULIB_NAMESPACE::ldexpl, long double, (long double, int));
 
 //SIGNATURE_CHECK (GNULIB_NAMESPACE::lgamma, double, (double));
 
-//SIGNATURE_CHECK (GNULIB_NAMESPACE::log10, double, (double));
+#if GNULIB_TEST_LOG10
+SIGNATURE_CHECK (GNULIB_NAMESPACE::log10, double, (double));
+#endif
 #if GNULIB_TEST_LOG10L
 SIGNATURE_CHECK (GNULIB_NAMESPACE::log10l, long double, (long double));
 #endif