]> Savannah Git Hosting - gnulib.git/commitdiff
modf-ieee: Work around test failures on *BSD, IRIX, OSF/1, Cygwin.
authorBruno Haible <bruno@clisp.org>
Mon, 27 Feb 2012 00:44:57 +0000 (01:44 +0100)
committerBruno Haible <bruno@clisp.org>
Mon, 27 Feb 2012 00:44:57 +0000 (01:44 +0100)
* m4/modf-ieee.m4: New file.
* m4/modf.m4 (gl_FUNC_MODF): If gl_FUNC_MODF_IEEE is present, test
whether modf works with NaN and Inf. Replace it if not.
* lib/math.in.h (modf): New declaration.
* lib/modf.c: New file.
* m4/math_h.m4 (gl_MATH_H): Test whether modf is declared.
(gl_MATH_H_DEFAULTS): Initialize GNULIB_MODF, REPLACE_MODF.
* modules/math (Makefile.am): Substitute GNULIB_MODF, REPLACE_MODF.
* modules/modf (Files): Add lib/modf.c.
(Depends-on): Add math, isfinite, trunc, isinf.
(configure.ac): Addrange to compile lib/modf.c if needed.
* modules/modf-ieee (Files): Add m4/modf-ieee.m4, m4/minus-zero.m4,
m4/signbit.m4.
(configure.ac): Invoke gl_FUNC_MODF_IEEE.
* tests/test-math-c++.cc: Check the declaration of modf.
* doc/posix-functions/modf.texi: Mention the modf-ieee module.

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

index 8c0d4fb4fade09bb4bcc41f1e23b7afd90109ef3..5485111011e324e757a485e0f8c0552a77f1e255 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,23 @@
 2012-02-26  Bruno Haible  <bruno@clisp.org>
 
+       modf-ieee: Work around test failures on *BSD, IRIX, OSF/1, Cygwin.
+       * m4/modf-ieee.m4: New file.
+       * m4/modf.m4 (gl_FUNC_MODF): If gl_FUNC_MODF_IEEE is present, test
+       whether modf works with NaN and Inf. Replace it if not.
+       * lib/math.in.h (modf): New declaration.
+       * lib/modf.c: New file.
+       * m4/math_h.m4 (gl_MATH_H): Test whether modf is declared.
+       (gl_MATH_H_DEFAULTS): Initialize GNULIB_MODF, REPLACE_MODF.
+       * modules/math (Makefile.am): Substitute GNULIB_MODF, REPLACE_MODF.
+       * modules/modf (Files): Add lib/modf.c.
+       (Depends-on): Add math, isfinite, trunc, isinf.
+       (configure.ac): Addrange to compile lib/modf.c if needed.
+       * modules/modf-ieee (Files): Add m4/modf-ieee.m4, m4/minus-zero.m4,
+       m4/signbit.m4.
+       (configure.ac): Invoke gl_FUNC_MODF_IEEE.
+       * tests/test-math-c++.cc: Check the declaration of modf.
+       * doc/posix-functions/modf.texi: Mention the modf-ieee module.
+
        Tests for module 'modfl-ieee'.
        * modules/modfl-ieee-tests: New file.
        * tests/test-modfl-ieee.c: New file.
index ba1eed664ea4cb13045bcdd010fce0633a952e58..b58b269221bb0ed2f45733dd1bf203961fb18e28 100644 (file)
@@ -4,12 +4,22 @@
 
 POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/modf.html}
 
-Gnulib module: modf
+Gnulib module: modf or modf-ieee
 
-Portability problems fixed by Gnulib:
+Portability problems fixed by either Gnulib module @code{modf} or @code{modf-ieee}:
 @itemize
 @end itemize
 
+Portability problems fixed by Gnulib module @code{modf-ieee}:
+@itemize
+@item
+This function has problems with a NaN argument on some platforms:
+NetBSD 5.1, Cygwin.
+@item
+This function has problems with infinite arguments on some platforms:
+FreeBSD 6.4, OpenBSD 4.9, IRIX 6.5, OSF/1 5.1.
+@end itemize
+
 Portability problems not fixed by Gnulib:
 @itemize
 @end itemize
index 553d5d459d163f0a8f4e405ed4d25d5fdab4829e..5fb014d1cd8fc2303ba5a94511ce848864fd48eb 100644 (file)
@@ -880,6 +880,26 @@ _GL_WARN_ON_USE (modff, "modff is unportable - "
 # endif
 #endif
 
+#if @GNULIB_MODF@
+# if @REPLACE_MODF@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef modf
+#   define modf rpl_modf
+#  endif
+_GL_FUNCDECL_RPL (modf, double, (double x, double *iptr) _GL_ARG_NONNULL ((2)));
+_GL_CXXALIAS_RPL (modf, double, (double x, double *iptr));
+# else
+_GL_CXXALIAS_SYS (modf, double, (double x, double *iptr));
+# endif
+_GL_CXXALIASWARN (modf);
+#elif defined GNULIB_POSIXCHECK
+# undef modf
+# if HAVE_RAW_DECL_MODF
+_GL_WARN_ON_USE (modf, "modf has portability problems - "
+                 "use gnulib module modf for portability");
+# endif
+#endif
+
 #if @GNULIB_MODFL@
 # if !@HAVE_MODFL@
 #  undef modfl
diff --git a/lib/modf.c b/lib/modf.c
new file mode 100644 (file)
index 0000000..19989e5
--- /dev/null
@@ -0,0 +1,44 @@
+/* Get signed integer and fractional parts of a floating-point number.
+   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
+modf (double x, double *iptr)
+{
+  if (isfinite (x))
+    {
+      double integer_part = trunc (x);
+      *iptr = integer_part;
+      return x - integer_part;
+    }
+  else
+    {
+      if (isinf (x))
+        {
+          *iptr = x;
+          return 1.0 / x;
+        }
+      else /* isnand (x) */
+        {
+          *iptr = x;
+          return x;
+        }
+    }
+}
index 5fe792c26e007c57c3d8aa8d82d08c8d0d4c4873..4a1980a4fb8c4043aacaa34225de3054149cb482 100644 (file)
@@ -1,4 +1,4 @@
-# math_h.m4 serial 63
+# math_h.m4 serial 64
 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,
@@ -42,7 +42,7 @@ AC_DEFUN([gl_MATH_H],
     [acosf acosl asinf asinl atanf atanl
      ceilf ceill copysign copysignf copysignl cosf cosl coshf
      expf expl fabsf fabsl floorf floorl fma fmaf fmal fmodf fmodl frexpf frexpl
-     ldexpf ldexpl logb logf logl log10f log10l modff modfl powf
+     ldexpf ldexpl logb logf logl log10f log10l modf modff modfl powf
      remainder remainderf remainderl
      rint rintf rintl round roundf roundl sinf sinl sinhf sqrtf sqrtl
      tanf tanl tanhf trunc truncf truncl])
@@ -103,6 +103,7 @@ AC_DEFUN([gl_MATH_H_DEFAULTS],
   GNULIB_LOGL=0;       AC_SUBST([GNULIB_LOGL])
   GNULIB_LOG10F=0;     AC_SUBST([GNULIB_LOG10F])
   GNULIB_LOG10L=0;     AC_SUBST([GNULIB_LOG10L])
+  GNULIB_MODF=0;       AC_SUBST([GNULIB_MODF])
   GNULIB_MODFF=0;      AC_SUBST([GNULIB_MODFF])
   GNULIB_MODFL=0;      AC_SUBST([GNULIB_MODFL])
   GNULIB_POWF=0;       AC_SUBST([GNULIB_POWF])
@@ -219,6 +220,7 @@ AC_DEFUN([gl_MATH_H_DEFAULTS],
   REPLACE_ISINF=0;             AC_SUBST([REPLACE_ISINF])
   REPLACE_ISNAN=0;             AC_SUBST([REPLACE_ISNAN])
   REPLACE_LDEXPL=0;            AC_SUBST([REPLACE_LDEXPL])
+  REPLACE_MODF=0;              AC_SUBST([REPLACE_MODF])
   REPLACE_NAN=0;               AC_SUBST([REPLACE_NAN])
   REPLACE_ROUND=0;             AC_SUBST([REPLACE_ROUND])
   REPLACE_ROUNDF=0;            AC_SUBST([REPLACE_ROUNDF])
diff --git a/m4/modf-ieee.m4 b/m4/modf-ieee.m4
new file mode 100644 (file)
index 0000000..b155f97
--- /dev/null
@@ -0,0 +1,15 @@
+# modf-ieee.m4 serial 1
+dnl Copyright (C) 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,
+dnl with or without modifications, as long as this notice is preserved.
+
+dnl This macro is in a separate file (not in modf.m4 and not inlined in the
+dnl module description), so that gl_FUNC_MODF can test whether 'aclocal' has
+dnl found uses of this macro.
+
+AC_DEFUN([gl_FUNC_MODF_IEEE],
+[
+  m4_divert_text([INIT_PREPARE], [gl_modf_required=ieee])
+  AC_REQUIRE([gl_FUNC_MODF])
+])
index d9767316722f6e2780ffdc2822d4a82db2ec71ea..43a66967583b014259b1fa9b6f99352228d670e1 100644 (file)
@@ -1,4 +1,4 @@
-# modf.m4 serial 1
+# modf.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,71 @@ dnl with or without modifications, as long as this notice is preserved.
 
 AC_DEFUN([gl_FUNC_MODF],
 [
+  m4_divert_text([DEFAULTS], [gl_modf_required=plain])
+  AC_REQUIRE([gl_MATH_H_DEFAULTS])
+
   dnl Determine MODF_LIBM.
   gl_MATHFUNC([modf], [double], [(double, double *)])
+
+  m4_ifdef([gl_FUNC_MODF_IEEE], [
+    if test $gl_modf_required = ieee && test $REPLACE_MODF = 0; then
+      AC_CACHE_CHECK([whether modf works according to ISO C 99 with IEC 60559],
+        [gl_cv_func_modf_ieee],
+        [
+          save_LIBS="$LIBS"
+          LIBS="$LIBS $MODF_LIBM"
+          AC_RUN_IFELSE(
+            [AC_LANG_SOURCE([[
+#ifndef __NO_MATH_INLINES
+# define __NO_MATH_INLINES 1 /* for glibc */
+#endif
+#include <math.h>
+]gl_DOUBLE_MINUS_ZERO_CODE[
+]gl_DOUBLE_SIGNBIT_CODE[
+/* Compare two numbers with ==.
+   This is a separate function because IRIX 6.5 "cc -O" miscompiles an
+   'x == x' test.  */
+static int
+numeric_equal (double x, double y)
+{
+  return x == y;
+}
+static double dummy (double x, double *iptr) { return 0; }
+double zero;
+double minus_one = - 1.0;
+int main (int argc, char *argv[])
+{
+  double (*my_modf) (double, double *) = argc ? modf : dummy;
+  int result = 0;
+  double i;
+  double f;
+  /* Test modf(NaN,...).
+     This test fails on NetBSD 5.1, Cygwin.  */
+  f = my_modf (zero / zero, &i);
+  if (numeric_equal (f, f))
+    result |= 1;
+  /* Test modf(-Inf,...).
+     This test fails on FreeBSD 6.4, OpenBSD 4.9, IRIX 6.5, OSF/1 5.1.  */
+  f = my_modf (minus_one / zero, &i);
+  if (!(f == 0.0) || (signbitd (minus_zerod) && !signbitd (f)))
+    result |= 2;
+  return result;
+}
+            ]])],
+            [gl_cv_func_modf_ieee=yes],
+            [gl_cv_func_modf_ieee=no],
+            [gl_cv_func_modf_ieee="guessing no"])
+          LIBS="$save_LIBS"
+        ])
+      case "$gl_cv_func_modf_ieee" in
+        *yes) ;;
+        *) REPLACE_MODF=1 ;;
+      esac
+    fi
+  ])
+  if test $REPLACE_MODF = 1; then
+    dnl Find libraries needed to link lib/modf.c.
+    AC_REQUIRE([gl_FUNC_TRUNC])
+    MODF_LIBM="$TRUNC_LIBM"
+  fi
 ])
index aa3011d56f3430581e8a3f062b02ad51ebf18b21..03f304f533f67da4f50e4054367f1fea9cfe8117 100644 (file)
@@ -72,6 +72,7 @@ math.h: math.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(
              -e 's/@''GNULIB_LOGL''@/$(GNULIB_LOGL)/g' \
              -e 's/@''GNULIB_LOG10F''@/$(GNULIB_LOG10F)/g' \
              -e 's/@''GNULIB_LOG10L''@/$(GNULIB_LOG10L)/g' \
+             -e 's/@''GNULIB_MODF''@/$(GNULIB_MODF)/g' \
              -e 's/@''GNULIB_MODFF''@/$(GNULIB_MODFF)/g' \
              -e 's/@''GNULIB_MODFL''@/$(GNULIB_MODFL)/g' \
              -e 's/@''GNULIB_POWF''@/$(GNULIB_POWF)/g' \
@@ -190,6 +191,7 @@ math.h: math.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(
              -e 's|@''REPLACE_ISNAN''@|$(REPLACE_ISNAN)|g' \
              -e 's|@''REPLACE_ITOLD''@|$(REPLACE_ITOLD)|g' \
              -e 's|@''REPLACE_LDEXPL''@|$(REPLACE_LDEXPL)|g' \
+             -e 's|@''REPLACE_MODF''@|$(REPLACE_MODF)|g' \
              -e 's|@''REPLACE_NAN''@|$(REPLACE_NAN)|g' \
              -e 's|@''REPLACE_ROUND''@|$(REPLACE_ROUND)|g' \
              -e 's|@''REPLACE_ROUNDF''@|$(REPLACE_ROUNDF)|g' \
index c0dffeb7637371e942e38b8001d2a8ea9e5967e5..fae62ebb3ed697bbf529081a6b1b54f437fad712 100644 (file)
@@ -2,13 +2,22 @@ Description:
 modf() function: get signed integer and fractional parts.
 
 Files:
+lib/modf.c
 m4/modf.m4
 m4/mathfunc.m4
 
 Depends-on:
+math
+isfinite        [test $REPLACE_MODF = 1]
+trunc           [test $REPLACE_MODF = 1]
+isinf           [test $REPLACE_MODF = 1]
 
 configure.ac:
 gl_FUNC_MODF
+if test $REPLACE_MODF = 1; then
+  AC_LIBOBJ([modf])
+fi
+gl_MATH_MODULE_INDICATOR([modf])
 
 Makefile.am:
 
index 5c102f8170aba27ee9176a629c22f5df8b479ff2..9513323e4f6f56de02a6a0a50f0d763f609067b7 100644 (file)
@@ -2,12 +2,16 @@ Description:
 modf() function according to ISO C 99 with IEC 60559.
 
 Files:
+m4/modf-ieee.m4
+m4/minus-zero.m4
+m4/signbit.m4
 
 Depends-on:
 modf
 fpieee
 
 configure.ac:
+gl_FUNC_MODF_IEEE
 
 Makefile.am:
 
index 947021588f1c6281519b4f7c16477f884c17be1f..241ae09db68a4ff747d8e825be41043b0349508a 100644 (file)
@@ -195,7 +195,9 @@ SIGNATURE_CHECK (GNULIB_NAMESPACE::log10f, float, (float));
 #if GNULIB_TEST_MODFF
 SIGNATURE_CHECK (GNULIB_NAMESPACE::modff, float, (float, float *));
 #endif
-//SIGNATURE_CHECK (GNULIB_NAMESPACE::modf, double, (double, double *));
+#if GNULIB_TEST_MODF
+SIGNATURE_CHECK (GNULIB_NAMESPACE::modf, double, (double, double *));
+#endif
 #if GNULIB_TEST_MODFL
 SIGNATURE_CHECK (GNULIB_NAMESPACE::modfl, long double,
                  (long double, long double *));