]> Savannah Git Hosting - gnulib.git/commitdiff
modff-ieee: Work around test failures on *BSD, IRIX, OSF/1, etc.
authorBruno Haible <bruno@clisp.org>
Mon, 27 Feb 2012 02:13:00 +0000 (03:13 +0100)
committerBruno Haible <bruno@clisp.org>
Mon, 27 Feb 2012 02:13:00 +0000 (03:13 +0100)
* m4/modff-ieee.m4: New file.
* m4/modff.m4 (gl_FUNC_MODFF): If gl_FUNC_MODFF_IEEE is present, test
whether modff works with NaN and Inf. Replace it if not.
* lib/math.in.h (modff): Override if REPLACE_MODFF is 1.
* m4/math_h.m4 (gl_MATH_H_DEFAULTS): Initialize REPLACE_MODFF.
* modules/math (Makefile.am): Substitute REPLACE_MODFF.
* modules/modff (configure.ac): Consider REPLACE_MODFF.
(Depends-on): Update dependencies.
* modules/modff-ieee (Files): Add m4/modff-ieee.m4, m4/minus-zero.m4,
m4/signbit.m4.
(Depends-on): Add modf-ieee.
(configure.ac): Invoke gl_FUNC_MODFF_IEEE.
* doc/posix-functions/modff.texi: Mention the modff-ieee module.

ChangeLog
doc/posix-functions/modff.texi
lib/math.in.h
m4/math_h.m4
m4/modff-ieee.m4 [new file with mode: 0644]
m4/modff.m4
modules/math
modules/modff
modules/modff-ieee

index 5485111011e324e757a485e0f8c0552a77f1e255..3e0fc21e664f95a523bbc157baa5025b13014645 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,20 @@
 2012-02-26  Bruno Haible  <bruno@clisp.org>
 
+       modff-ieee: Work around test failures on *BSD, IRIX, OSF/1, etc.
+       * m4/modff-ieee.m4: New file.
+       * m4/modff.m4 (gl_FUNC_MODFF): If gl_FUNC_MODFF_IEEE is present, test
+       whether modff works with NaN and Inf. Replace it if not.
+       * lib/math.in.h (modff): Override if REPLACE_MODFF is 1.
+       * m4/math_h.m4 (gl_MATH_H_DEFAULTS): Initialize REPLACE_MODFF.
+       * modules/math (Makefile.am): Substitute REPLACE_MODFF.
+       * modules/modff (configure.ac): Consider REPLACE_MODFF.
+       (Depends-on): Update dependencies.
+       * modules/modff-ieee (Files): Add m4/modff-ieee.m4, m4/minus-zero.m4,
+       m4/signbit.m4.
+       (Depends-on): Add modf-ieee.
+       (configure.ac): Invoke gl_FUNC_MODFF_IEEE.
+       * doc/posix-functions/modff.texi: Mention the modff-ieee module.
+
        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
index d462a045bd51c9910e5fcc9d2b0b7c822c15ba08..4618b9504b8b748df23757c087ccba4d9968d110 100644 (file)
@@ -4,9 +4,9 @@
 
 POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/modff.html}
 
-Gnulib module: modff
+Gnulib module: modff or modff-ieee
 
-Portability problems fixed by Gnulib:
+Portability problems fixed by either Gnulib module @code{modff} or @code{modff-ieee}:
 @itemize
 @item
 This function is missing on some platforms:
@@ -16,6 +16,16 @@ This function is only defined as a buggy macro with arguments on some platforms:
 MSVC 9.
 @end itemize
 
+Portability problems fixed by Gnulib module @code{modff-ieee}:
+@itemize
+@item
+This function has problems with a NaN argument on some platforms:
+NetBSD 5.1, OpenBSD 4.9, Solaris 9, Cygwin.
+@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
index 5fb014d1cd8fc2303ba5a94511ce848864fd48eb..b5fc9164da3c57548987284eada19e779e4c3b98 100644 (file)
@@ -866,11 +866,20 @@ _GL_WARN_ON_USE (log10l, "log10l is unportable - "
 
 
 #if @GNULIB_MODFF@
-# if !@HAVE_MODFF@
-#  undef modff
+# if @REPLACE_MODFF@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef modff
+#   define modff rpl_modff
+#  endif
+_GL_FUNCDECL_RPL (modff, float, (float x, float *iptr) _GL_ARG_NONNULL ((2)));
+_GL_CXXALIAS_RPL (modff, float, (float x, float *iptr));
+# else
+#  if !@HAVE_MODFF@
+#   undef modff
 _GL_FUNCDECL_SYS (modff, float, (float x, float *iptr) _GL_ARG_NONNULL ((2)));
-# endif
+#  endif
 _GL_CXXALIAS_SYS (modff, float, (float x, float *iptr));
+# endif
 _GL_CXXALIASWARN (modff);
 #elif defined GNULIB_POSIXCHECK
 # undef modff
index 4a1980a4fb8c4043aacaa34225de3054149cb482..8afa4ba7df7df06d580680e459e1a4ad40968ad8 100644 (file)
@@ -1,4 +1,4 @@
-# math_h.m4 serial 64
+# math_h.m4 serial 65
 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,
@@ -221,6 +221,7 @@ AC_DEFUN([gl_MATH_H_DEFAULTS],
   REPLACE_ISNAN=0;             AC_SUBST([REPLACE_ISNAN])
   REPLACE_LDEXPL=0;            AC_SUBST([REPLACE_LDEXPL])
   REPLACE_MODF=0;              AC_SUBST([REPLACE_MODF])
+  REPLACE_MODFF=0;             AC_SUBST([REPLACE_MODFF])
   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/modff-ieee.m4 b/m4/modff-ieee.m4
new file mode 100644 (file)
index 0000000..7e0cc10
--- /dev/null
@@ -0,0 +1,15 @@
+# modff-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 modff.m4 and not inlined in the
+dnl module description), so that gl_FUNC_MODFF can test whether 'aclocal' has
+dnl found uses of this macro.
+
+AC_DEFUN([gl_FUNC_MODFF_IEEE],
+[
+  m4_divert_text([INIT_PREPARE], [gl_modff_required=ieee])
+  AC_REQUIRE([gl_FUNC_MODFF])
+])
index 6bccc75924d42195ddde4d2edc5746df43e2e0fe..993e5690058b988ad8fd8625725d152b3b01a761 100644 (file)
@@ -1,4 +1,4 @@
-# modff.m4 serial 2
+# modff.m4 serial 3
 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,7 @@ dnl with or without modifications, as long as this notice is preserved.
 
 AC_DEFUN([gl_FUNC_MODFF],
 [
+  m4_divert_text([DEFAULTS], [gl_modff_required=plain])
   AC_REQUIRE([gl_MATH_H_DEFAULTS])
   AC_REQUIRE([gl_FUNC_MODF])
 
@@ -13,9 +14,69 @@ AC_DEFUN([gl_FUNC_MODFF],
   dnl exists, is defined in the same library as modf(). This is not the case
   dnl on FreeBSD, NetBSD, OpenBSD.
   gl_MATHFUNC([modff], [float], [(float, float *)])
-  if test $gl_cv_func_modff_no_libm = no \
-     && test $gl_cv_func_modff_in_libm = no; then
+  if test $gl_cv_func_modff_no_libm = yes \
+     || test $gl_cv_func_modff_in_libm = yes; then
+    m4_ifdef([gl_FUNC_MODFF_IEEE], [
+      if test $gl_modff_required = ieee && test $REPLACE_MODFF = 0; then
+        AC_CACHE_CHECK([whether modff works according to ISO C 99 with IEC 60559],
+          [gl_cv_func_modff_ieee],
+          [
+            save_LIBS="$LIBS"
+            LIBS="$LIBS $MODFF_LIBM"
+            AC_RUN_IFELSE(
+              [AC_LANG_SOURCE([[
+#ifndef __NO_MATH_INLINES
+# define __NO_MATH_INLINES 1 /* for glibc */
+#endif
+#include <math.h>
+]gl_FLOAT_MINUS_ZERO_CODE[
+]gl_FLOAT_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 (float x, float y)
+{
+  return x == y;
+}
+static float dummy (float x, float *iptr) { return 0; }
+float zero;
+float minus_one = - 1.0f;
+int main (int argc, char *argv[])
+{
+  float (*my_modff) (float, float *) = argc ? modff : dummy;
+  int result = 0;
+  float i;
+  float f;
+  /* Test modff(NaN,...).
+     This test fails on NetBSD 5.1, OpenBSD 4.9, Solaris 9, Cygwin.  */
+  f = my_modff (zero / zero, &i);
+  if (numeric_equal (f, f))
+    result |= 1;
+  /* Test modff(-Inf,...).
+     This test fails on IRIX 6.5, OSF/1 5.1, mingw.  */
+  f = my_modff (minus_one / zero, &i);
+  if (!(f == 0.0f) || (signbitf (minus_zerof) && !signbitf (f)))
+    result |= 2;
+  return result;
+}
+              ]])],
+              [gl_cv_func_modff_ieee=yes],
+              [gl_cv_func_modff_ieee=no],
+              [gl_cv_func_modff_ieee="guessing no"])
+            LIBS="$save_LIBS"
+          ])
+        case "$gl_cv_func_modff_ieee" in
+          *yes) ;;
+          *) REPLACE_MODFF=1 ;;
+        esac
+      fi
+    ])
+  else
     HAVE_MODFF=0
+  fi
+  if test $HAVE_MODFF = 0 || test $REPLACE_MODFF = 1; then
+    dnl Find libraries needed to link lib/modff.c.
     MODFF_LIBM="$MODF_LIBM"
   fi
   AC_SUBST([MODFF_LIBM])
index 03f304f533f67da4f50e4054367f1fea9cfe8117..8e8ff5689f4aa384f3a77e5df26b7cdae15793d2 100644 (file)
@@ -192,6 +192,7 @@ math.h: math.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(
              -e 's|@''REPLACE_ITOLD''@|$(REPLACE_ITOLD)|g' \
              -e 's|@''REPLACE_LDEXPL''@|$(REPLACE_LDEXPL)|g' \
              -e 's|@''REPLACE_MODF''@|$(REPLACE_MODF)|g' \
+             -e 's|@''REPLACE_MODFF''@|$(REPLACE_MODFF)|g' \
              -e 's|@''REPLACE_NAN''@|$(REPLACE_NAN)|g' \
              -e 's|@''REPLACE_ROUND''@|$(REPLACE_ROUND)|g' \
              -e 's|@''REPLACE_ROUNDF''@|$(REPLACE_ROUNDF)|g' \
index 15512136fe459baadbc36c48f72b2a9c7d764ea2..894bf67dc0ce14a2a507739ae72f6040cf2f7e3c 100644 (file)
@@ -8,11 +8,11 @@ m4/mathfunc.m4
 
 Depends-on:
 math
-modf            [test $HAVE_MODFF = 0]
+modf            [test $HAVE_MODFF = 0 || test $REPLACE_MODFF = 1]
 
 configure.ac:
 gl_FUNC_MODFF
-if test $HAVE_MODFF = 0; then
+if test $HAVE_MODFF = 0 || test $REPLACE_MODFF = 1; then
   AC_LIBOBJ([modff])
 fi
 gl_MATH_MODULE_INDICATOR([modff])
index eee40b9f745d815b5704f1235c8c283e136e19a6..d6c9b26eb67a318bb14424319014a9d972cb3df5 100644 (file)
@@ -2,12 +2,17 @@ Description:
 modff() function according to ISO C 99 with IEC 60559.
 
 Files:
+m4/modff-ieee.m4
+m4/minus-zero.m4
+m4/signbit.m4
 
 Depends-on:
 modff
 fpieee
+modf-ieee       [test $HAVE_MODFF = 0]
 
 configure.ac:
+gl_FUNC_MODFF_IEEE
 
 Makefile.am: