changeset 16471:1f4605f1f3ae

modfl-ieee: Work around test failures on IRIX, OSF/1, mingw. * m4/modfl-ieee.m4: New file. * m4/modfl.m4 (gl_FUNC_MODFL): If gl_FUNC_MODFL_IEEE is present, test whether modfl works with Inf. Replace it if not. * lib/math.in.h (modfl): Override if REPLACE_MODFF is 1. * m4/math_h.m4 (gl_MATH_H_DEFAULTS): Initialize REPLACE_MODFL. * modules/math (Makefile.am): Substitute REPLACE_MODFL. * modules/modfl (configure.ac): Consider REPLACE_MODFL. (Depends-on): Update dependencies. * modules/modfl-ieee (Files): Add m4/modfl-ieee.m4, m4/minus-zero.m4, m4/signbit.m4. (configure.ac): Invoke gl_FUNC_MODFL_IEEE. * doc/posix-functions/modfl.texi: Mention the modfl-ieee module.
author Bruno Haible <bruno@clisp.org>
date Mon, 27 Feb 2012 05:03:10 +0100
parents 2b6492cddc6a
children 3aacf1725823
files ChangeLog doc/posix-functions/modfl.texi lib/math.in.h m4/math_h.m4 m4/modfl-ieee.m4 m4/modfl.m4 modules/math modules/modfl modules/modfl-ieee
diffstat 9 files changed, 120 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,19 @@
 2012-02-26  Bruno Haible  <bruno@clisp.org>
 
+	modfl-ieee: Work around test failures on IRIX, OSF/1, mingw.
+	* m4/modfl-ieee.m4: New file.
+	* m4/modfl.m4 (gl_FUNC_MODFL): If gl_FUNC_MODFL_IEEE is present, test
+	whether modfl works with Inf. Replace it if not.
+	* lib/math.in.h (modfl): Override if REPLACE_MODFF is 1.
+	* m4/math_h.m4 (gl_MATH_H_DEFAULTS): Initialize REPLACE_MODFL.
+	* modules/math (Makefile.am): Substitute REPLACE_MODFL.
+	* modules/modfl (configure.ac): Consider REPLACE_MODFL.
+	(Depends-on): Update dependencies.
+	* modules/modfl-ieee (Files): Add m4/modfl-ieee.m4, m4/minus-zero.m4,
+	m4/signbit.m4.
+	(configure.ac): Invoke gl_FUNC_MODFL_IEEE.
+	* doc/posix-functions/modfl.texi: Mention the modfl-ieee module.
+
 	modfl-ieee: Fix dependencies.
 	* modules/modfl-ieee (Depends-on): Add modf-ieee.
 
--- a/doc/posix-functions/modfl.texi
+++ b/doc/posix-functions/modfl.texi
@@ -4,9 +4,9 @@
 
 POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/modfl.html}
 
-Gnulib module: modfl
+Gnulib module: modfl or modfl-ieee
 
-Portability problems fixed by Gnulib:
+Portability problems fixed by either Gnulib module @code{modfl} or @code{modfl-ieee}:
 @itemize
 @item
 This function is missing on some platforms:
@@ -16,6 +16,13 @@
 MSVC 9.
 @end itemize
 
+Portability problems fixed by Gnulib module @code{modfl-ieee}:
+@itemize
+@item
+This function has problems with infinite arguments on some platforms:
+IRIX 6.5, OSF/1 5.1, mingw.
+@end itemize
+
 Portability problems not fixed by Gnulib:
 @itemize
 @end itemize
--- a/lib/math.in.h
+++ b/lib/math.in.h
@@ -910,12 +910,22 @@
 #endif
 
 #if @GNULIB_MODFL@
-# if !@HAVE_MODFL@
-#  undef modfl
+# if @REPLACE_MODFL@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef modfl
+#   define modfl rpl_modfl
+#  endif
+_GL_FUNCDECL_RPL (modfl, long double, (long double x, long double *iptr)
+                                      _GL_ARG_NONNULL ((2)));
+_GL_CXXALIAS_RPL (modfl, long double, (long double x, long double *iptr));
+# else
+#  if !@HAVE_MODFL@
+#   undef modfl
 _GL_FUNCDECL_SYS (modfl, long double, (long double x, long double *iptr)
                                       _GL_ARG_NONNULL ((2)));
+#  endif
+_GL_CXXALIAS_SYS (modfl, long double, (long double x, long double *iptr));
 # endif
-_GL_CXXALIAS_SYS (modfl, long double, (long double x, long double *iptr));
 _GL_CXXALIASWARN (modfl);
 #elif defined GNULIB_POSIXCHECK
 # undef modfl
--- a/m4/math_h.m4
+++ b/m4/math_h.m4
@@ -1,4 +1,4 @@
-# math_h.m4 serial 65
+# math_h.m4 serial 66
 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,
@@ -222,6 +222,7 @@
   REPLACE_LDEXPL=0;            AC_SUBST([REPLACE_LDEXPL])
   REPLACE_MODF=0;              AC_SUBST([REPLACE_MODF])
   REPLACE_MODFF=0;             AC_SUBST([REPLACE_MODFF])
+  REPLACE_MODFL=0;             AC_SUBST([REPLACE_MODFL])
   REPLACE_NAN=0;               AC_SUBST([REPLACE_NAN])
   REPLACE_ROUND=0;             AC_SUBST([REPLACE_ROUND])
   REPLACE_ROUNDF=0;            AC_SUBST([REPLACE_ROUNDF])
new file mode 100644
--- /dev/null
+++ b/m4/modfl-ieee.m4
@@ -0,0 +1,15 @@
+# modfl-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 modfl.m4 and not inlined in the
+dnl module description), so that gl_FUNC_MODFL can test whether 'aclocal' has
+dnl found uses of this macro.
+
+AC_DEFUN([gl_FUNC_MODFL_IEEE],
+[
+  m4_divert_text([INIT_PREPARE], [gl_modfl_required=ieee])
+  AC_REQUIRE([gl_FUNC_MODFL])
+])
--- a/m4/modfl.m4
+++ b/m4/modfl.m4
@@ -6,6 +6,7 @@
 
 AC_DEFUN([gl_FUNC_MODFL],
 [
+  m4_divert_text([DEFAULTS], [gl_modfl_required=plain])
   AC_REQUIRE([gl_MATH_H_DEFAULTS])
   AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE])
 
@@ -13,9 +14,63 @@
   dnl exists, is defined in the same library as modf(). This is not the case
   dnl on FreeBSD, Solaris.
   gl_MATHFUNC([modfl], [long double], [(long double, long double *)])
-  if test $gl_cv_func_modfl_no_libm = no \
-     && test $gl_cv_func_modfl_in_libm = no; then
+  if test $gl_cv_func_modfl_no_libm = yes \
+     || test $gl_cv_func_modfl_in_libm = yes; then
+    m4_ifdef([gl_FUNC_MODFL_IEEE], [
+      if test $gl_modfl_required = ieee && test $REPLACE_MODFL = 0; then
+        AC_CACHE_CHECK([whether modfl works according to ISO C 99 with IEC 60559],
+          [gl_cv_func_modfl_ieee],
+          [
+            save_LIBS="$LIBS"
+            LIBS="$LIBS $MODFL_LIBM"
+            AC_RUN_IFELSE(
+              [AC_LANG_SOURCE([[
+#ifndef __NO_MATH_INLINES
+# define __NO_MATH_INLINES 1 /* for glibc */
+#endif
+#include <math.h>
+]gl_LONG_DOUBLE_MINUS_ZERO_CODE[
+]gl_LONG_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 (long double x, long double y)
+{
+  return x == y;
+}
+static long double dummy (long double x, long double *iptr) { return 0; }
+long double zero;
+long double minus_one = - 1.0L;
+int main (int argc, char *argv[])
+{
+  long double (*my_modfl) (long double, long double *) = argc ? modfl : dummy;
+  long double i;
+  long double f;
+  /* Test modfl(-Inf,...).
+     This test fails on IRIX 6.5, OSF/1 5.1, mingw.  */
+  f = my_modfl (minus_one / zero, &i);
+  if (!(f == 0.0L) || (signbitl (minus_zerol) && !signbitl (f)))
+    return 1;
+  return 0;
+}
+              ]])],
+              [gl_cv_func_modfl_ieee=yes],
+              [gl_cv_func_modfl_ieee=no],
+              [gl_cv_func_modfl_ieee="guessing no"])
+            LIBS="$save_LIBS"
+          ])
+        case "$gl_cv_func_modfl_ieee" in
+          *yes) ;;
+          *) REPLACE_MODFL=1 ;;
+        esac
+      fi
+    ])
+  else
     HAVE_MODFL=0
+  fi
+  if test $HAVE_MODFL = 0 || test $REPLACE_MODFL = 1; then
+    dnl Find libraries needed to link lib/modfl.c.
     if test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1; then
       AC_REQUIRE([gl_FUNC_MODF])
       MODFL_LIBM="$MODF_LIBM"
--- a/modules/math
+++ b/modules/math
@@ -193,6 +193,7 @@
 	      -e 's|@''REPLACE_LDEXPL''@|$(REPLACE_LDEXPL)|g' \
 	      -e 's|@''REPLACE_MODF''@|$(REPLACE_MODF)|g' \
 	      -e 's|@''REPLACE_MODFF''@|$(REPLACE_MODFF)|g' \
+	      -e 's|@''REPLACE_MODFL''@|$(REPLACE_MODFL)|g' \
 	      -e 's|@''REPLACE_NAN''@|$(REPLACE_NAN)|g' \
 	      -e 's|@''REPLACE_ROUND''@|$(REPLACE_ROUND)|g' \
 	      -e 's|@''REPLACE_ROUNDF''@|$(REPLACE_ROUNDF)|g' \
--- a/modules/modfl
+++ b/modules/modfl
@@ -8,14 +8,14 @@
 
 Depends-on:
 math
-modf            [test $HAVE_MODFL = 0 && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1]
-isfinite        [test $HAVE_MODFL = 0 && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 0]
-truncl          [test $HAVE_MODFL = 0 && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 0]
-isinf           [test $HAVE_MODFL = 0 && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 0]
+modf            [{ test $HAVE_MODFL = 0 || test $REPLACE_MODFL = 1; } && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1]
+isfinite        [{ test $HAVE_MODFL = 0 || test $REPLACE_MODFL = 1; } && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 0]
+truncl          [{ test $HAVE_MODFL = 0 || test $REPLACE_MODFL = 1; } && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 0]
+isinf           [{ test $HAVE_MODFL = 0 || test $REPLACE_MODFL = 1; } && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 0]
 
 configure.ac:
 gl_FUNC_MODFL
-if test $HAVE_MODFL = 0; then
+if test $HAVE_MODFL = 0 || test $REPLACE_MODFL = 1; then
   AC_LIBOBJ([modfl])
 fi
 gl_MATH_MODULE_INDICATOR([modfl])
--- a/modules/modfl-ieee
+++ b/modules/modfl-ieee
@@ -2,6 +2,9 @@
 modfl() function according to ISO C 99 with IEC 60559.
 
 Files:
+m4/modfl-ieee.m4
+m4/minus-zero.m4
+m4/signbit.m4
 
 Depends-on:
 modfl
@@ -9,6 +12,7 @@
 modf-ieee       [test $HAVE_MODFL = 0 && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1]
 
 configure.ac:
+gl_FUNC_MODFL_IEEE
 
 Makefile.am: