bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

log, logf, logl: more tests


From: Bruno Haible
Subject: log, logf, logl: more tests
Date: Sat, 10 Mar 2012 11:10:19 +0100
User-agent: KMail/4.7.4 (Linux/3.1.0-1.2-desktop; KDE/4.7.4; x86_64; ; )

Enhanced tests for the log(), logf(), logl() function show bugs on
OSF/1 5.1:
  log(-0.0) = NaN
  logf(-0.0f) = NaN
  logl(-0.0L) = NaN
This series of patches adds workarounds and the tests.


2012-03-10  Bruno Haible  <address@hidden>

        log* tests: More tests.
        * tests/test-log.h: New file.
        * tests/test-log.c: Include <float.h>, minus-zero.h, test-log.h.
        (main): Invoke test_function.
        * tests/test-logf.c: Include <float.h>, minus-zero.h, test-log.h.
        (main): Invoke test_function.
        * tests/test-logl.c: Include <float.h>, minus-zero.h, test-log.h.
        (main): Invoke test_function.
        * modules/log-tests (Files): Add tests/test-log.h, tests/minus-zero.h,
        tests/randomd.c.
        (Makefile.am): Add randomd.c to test_log_SOURCES.
        * modules/logf-tests (Files): Add tests/test-log.h, tests/minus-zero.h,
        tests/randomf.c.
        (Makefile.am): Add randomf.c to test_logf_SOURCES.
        * modules/logl-tests (Files): Add tests/test-log.h, tests/minus-zero.h,
        tests/randoml.c.
        (Depends-on): Add 'float'.
        (Makefile.am): Add randoml.c to test_logl_SOURCES.

2012-03-09  Bruno Haible  <address@hidden>

        logl: Work around OSF/1 5.1 bug.
        * lib/math.in.h (logl): Override if REPLACE_LOGL is 1.
        * lib/logl.c (logl): If logf exists, use it and provide just the
        workaround.
        * m4/logl.m4 (gl_FUNC_LOGL_WORKS): New macro.
        (gl_FUNC_LOGL): Invoke it. Set REPLACE_LOGL.
        * m4/math_h.m4 (gl_MATH_H_DEFAULTS): Initialize REPLACE_LOGL.
        * modules/math (Makefile.am): Substitute REPLACE_LOGL.
        * modules/logl (configure.ac): Consider REPLACE_LOGL.
        (Depends-on): Update conditions.
        * doc/posix-functions/logl.texi: Mention the OSF/1 5.1 problem.

2012-03-09  Bruno Haible  <address@hidden>

        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  <address@hidden>

        log: Work around OSF/1 5.1 bug.
        * lib/math.in.h (log): New declaration.
        * lib/log.c: New file.
        * m4/log.m4 (gl_FUNC_LOG_WORKS): New macro.
        (gl_FUNC_LOG): Invoke it. Set REPLACE_LOG.
        * m4/math_h.m4 (gl_MATH_H): Test whether log is declared.
        (gl_MATH_H_DEFAULTS): Initialize GNULIB_LOG, REPLACE_LOG.
        * modules/math (Makefile.am): Substitute GNULIB_LOG, REPLACE_LOG.
        * modules/log (Files): Add lib/log.c.
        (Depends-on): Add math.
        (configure.ac): If REPLACE_LOG is 1, compile an override.
        * tests/test-math-c++.cc: Check the declaration of log.
        * doc/posix-functions/log.texi: Mention the OSF/1 5.1 problem.

Here are the essential parts, in lib/:
============================== lib/log.c ================================
/* Logarithm.
   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
log (double x)
#undef log
{
  /* Work around the OSF/1 5.1 bug.  */
  if (x == 0.0)
    /* Return -Infinity.  */
    return -1.0 / 0.0;
  return log (x);
}
=========================================================================
diff -r -u gnulib/lib/logf.c gnulib/lib/logf.c
--- gnulib/lib/logf.c   2012-01-02 19:02:16.000000000 +0100
+++ gnulib/lib/logf.c   2012-03-10 10:37:41.000000000 +0100
@@ -21,6 +21,15 @@
 
 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
 }
diff -r -u gnulib/lib/logl.c gnulib/lib/logl.c
--- gnulib/lib/logl.c   2012-02-29 13:25:44.000000000 +0100
+++ gnulib/lib/logl.c   2012-03-10 10:37:41.000000000 +0100
@@ -26,6 +26,19 @@
   return log (x);
 }
 
+#elif HAVE_LOGL
+
+long double
+logl (long double x)
+# undef logl
+{
+  /* Work around the OSF/1 5.1 bug.  */
+  if (x == 0.0L)
+    /* Return -Infinity.  */
+    return -1.0L / 0.0L;
+  return logl (x);
+}
+
 #else
 
 /* Code based on glibc/sysdeps/ieee754/ldbl-128/e_logl.c.  */
diff -r -u gnulib/lib/math.in.h gnulib/lib/math.in.h
--- gnulib/lib/math.in.h        2012-03-09 10:31:42.000000000 +0100
+++ gnulib/lib/math.in.h        2012-03-10 10:37:41.000000000 +0100
@@ -1122,11 +1122,20 @@
 
 
 #if @GNULIB_LOGF@
-# if address@hidden@
-#  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 address@hidden@
+#   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
@@ -1136,12 +1145,41 @@
 # endif
 #endif
 
+#if @GNULIB_LOG@
+# if @REPLACE_LOG@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef log
+#   define log rpl_log
+#  endif
+_GL_FUNCDECL_RPL (log, double, (double x));
+_GL_CXXALIAS_RPL (log, double, (double x));
+# else
+_GL_CXXALIAS_SYS (log, double, (double x));
+# endif
+_GL_CXXALIASWARN (log);
+#elif defined GNULIB_POSIXCHECK
+# undef log
+# if HAVE_RAW_DECL_LOG
+_GL_WARN_ON_USE (log, "log has portability problems - "
+                 "use gnulib module log for portability");
+# endif
+#endif
+
 #if @GNULIB_LOGL@
-# if address@hidden@ || address@hidden@
-#  undef logl
+# if @REPLACE_LOGL@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef logl
+#   define logl rpl_logl
+#  endif
+_GL_FUNCDECL_RPL (logl, long double, (long double x));
+_GL_CXXALIAS_RPL (logl, long double, (long double x));
+# else
+#  if address@hidden@ || address@hidden@
+#   undef logl
 _GL_FUNCDECL_SYS (logl, long double, (long double x));
-# endif
+#  endif
 _GL_CXXALIAS_SYS (logl, long double, (long double x));
+# endif
 _GL_CXXALIASWARN (logl);
 #elif defined GNULIB_POSIXCHECK
 # undef logl




reply via email to

[Prev in Thread] Current Thread [Next in Thread]