summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2012-02-27 01:44:57 +0100
committerBruno Haible <bruno@clisp.org>2012-02-27 01:44:57 +0100
commitb5cc9885b4b5a247870adf0ed9b9f4a5a3347a26 (patch)
treec9f852a62c0086a9c8f4552f7db42c67781b18f5
parent8f32a5c4f21e3a360b1a756a88880985215d67db (diff)
downloadgnulib-b5cc9885b4b5a247870adf0ed9b9f4a5a3347a26.tar.gz
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.
-rw-r--r--ChangeLog18
-rw-r--r--doc/posix-functions/modf.texi14
-rw-r--r--lib/math.in.h20
-rw-r--r--lib/modf.c44
-rw-r--r--m4/math_h.m46
-rw-r--r--m4/modf-ieee.m415
-rw-r--r--m4/modf.m467
-rw-r--r--modules/math2
-rw-r--r--modules/modf9
-rw-r--r--modules/modf-ieee4
-rw-r--r--tests/test-math-c++.cc4
11 files changed, 197 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog
index 8c0d4fb4fa..5485111011 100644
--- 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.
diff --git a/doc/posix-functions/modf.texi b/doc/posix-functions/modf.texi
index ba1eed664e..b58b269221 100644
--- a/doc/posix-functions/modf.texi
+++ b/doc/posix-functions/modf.texi
@@ -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
diff --git a/lib/math.in.h b/lib/math.in.h
index 553d5d459d..5fb014d1cd 100644
--- a/lib/math.in.h
+++ b/lib/math.in.h
@@ -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
index 0000000000..19989e5b8d
--- /dev/null
+++ b/lib/modf.c
@@ -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;
+ }
+ }
+}
diff --git a/m4/math_h.m4 b/m4/math_h.m4
index 5fe792c26e..4a1980a4fb 100644
--- a/m4/math_h.m4
+++ b/m4/math_h.m4
@@ -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
index 0000000000..b155f97a88
--- /dev/null
+++ b/m4/modf-ieee.m4
@@ -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])
+])
diff --git a/m4/modf.m4 b/m4/modf.m4
index d976731672..43a6696758 100644
--- a/m4/modf.m4
+++ b/m4/modf.m4
@@ -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
])
diff --git a/modules/math b/modules/math
index aa3011d56f..03f304f533 100644
--- a/modules/math
+++ b/modules/math
@@ -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' \
diff --git a/modules/modf b/modules/modf
index c0dffeb763..fae62ebb3e 100644
--- a/modules/modf
+++ b/modules/modf
@@ -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:
diff --git a/modules/modf-ieee b/modules/modf-ieee
index 5c102f8170..9513323e4f 100644
--- a/modules/modf-ieee
+++ b/modules/modf-ieee
@@ -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:
diff --git a/tests/test-math-c++.cc b/tests/test-math-c++.cc
index 947021588f..241ae09db6 100644
--- a/tests/test-math-c++.cc
+++ b/tests/test-math-c++.cc
@@ -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 *));