fmodf-ieee: Work around test failure on OSF/1.
authorBruno Haible <bruno@clisp.org>
Mon, 27 Feb 2012 12:18:57 +0000 (13:18 +0100)
committerBruno Haible <bruno@clisp.org>
Mon, 27 Feb 2012 12:18:57 +0000 (13:18 +0100)
* m4/fmodf-ieee.m4: New file.
* m4/fmodf.m4 (gl_FUNC_FMODF): If gl_FUNC_FMODF_IEEE is present, test
whether fmodf works with zero arguments. Replace it if not.
* lib/math.in.h (fmodf): Override if REPLACE_FMODF is 1.
* m4/math_h.m4 (gl_MATH_H_DEFAULTS): Initialize REPLACE_FMODF.
* modules/math (Makefile.am): Substitute REPLACE_FMODF.
* modules/fmodf (configure.ac): Consider REPLACE_FMODF.
(Depends-on): Update dependencies.
* modules/fmodf-ieee (Files): Add m4/fmodf-ieee.m4.
(configure.ac): Invoke gl_FUNC_FMODF_IEEE.
* doc/posix-functions/fmodf.texi: Mention the problem on OSF/1.

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

index ea481d26c6eb519762c37c054dc026f443d00f19..cbd22733d6fb25d6212531f227d4300ff0f76a15 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,18 @@
 2012-02-27  Bruno Haible  <bruno@clisp.org>
 
+       fmodf-ieee: Work around test failure on OSF/1.
+       * m4/fmodf-ieee.m4: New file.
+       * m4/fmodf.m4 (gl_FUNC_FMODF): If gl_FUNC_FMODF_IEEE is present, test
+       whether fmodf works with zero arguments. Replace it if not.
+       * lib/math.in.h (fmodf): Override if REPLACE_FMODF is 1.
+       * m4/math_h.m4 (gl_MATH_H_DEFAULTS): Initialize REPLACE_FMODF.
+       * modules/math (Makefile.am): Substitute REPLACE_FMODF.
+       * modules/fmodf (configure.ac): Consider REPLACE_FMODF.
+       (Depends-on): Update dependencies.
+       * modules/fmodf-ieee (Files): Add m4/fmodf-ieee.m4.
+       (configure.ac): Invoke gl_FUNC_FMODF_IEEE.
+       * doc/posix-functions/fmodf.texi: Mention the problem on OSF/1.
+
        fmodf-ieee: Work around test failure on MSVC 9.
        * modules/fmodf-ieee (Depends-on): Add fmod-ieee.
        * doc/posix-functions/fmodf.texi: Mention the fmodf-ieee module.
index 68ff51b65943fa5743f5394cfba16c956282fc48..27e6638ea6f70abf62994ce307a4eb5d2f01f6ae 100644 (file)
@@ -19,6 +19,9 @@ MSVC 9.
 Portability problems fixed by Gnulib module @code{fmodf-ieee}:
 @itemize
 @item
+This function has problems when the second argument is zero on some platforms:
+OSF/1 5.1.
+@item
 This function has problems when the first argument is minus zero on some
 platforms:
 MSVC 9.
index abbfc6291aee2f6e0bbb1608c2d241083885b5a4..219104116bc5513d48fd5ed5f4339d5a9319dab9 100644 (file)
@@ -615,11 +615,20 @@ _GL_WARN_ON_USE (fmal, "fmal is unportable - "
 
 
 #if @GNULIB_FMODF@
-# if !@HAVE_FMODF@
-#  undef fmodf
+# if @REPLACE_FMODF@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef fmodf
+#   define fmodf rpl_fmodf
+#  endif
+_GL_FUNCDECL_RPL (fmodf, float, (float x, float y));
+_GL_CXXALIAS_RPL (fmodf, float, (float x, float y));
+# else
+#  if !@HAVE_FMODF@
+#   undef fmodf
 _GL_FUNCDECL_SYS (fmodf, float, (float x, float y));
-# endif
+#  endif
 _GL_CXXALIAS_SYS (fmodf, float, (float x, float y));
+# endif
 _GL_CXXALIASWARN (fmodf);
 #elif defined GNULIB_POSIXCHECK
 # undef fmodf
diff --git a/m4/fmodf-ieee.m4 b/m4/fmodf-ieee.m4
new file mode 100644 (file)
index 0000000..883b0be
--- /dev/null
@@ -0,0 +1,15 @@
+# fmodf-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 fmodf.m4 and not inlined in the
+dnl module description), so that gl_FUNC_FMODF can test whether 'aclocal' has
+dnl found uses of this macro.
+
+AC_DEFUN([gl_FUNC_FMODF_IEEE],
+[
+  m4_divert_text([INIT_PREPARE], [gl_fmodf_required=ieee])
+  AC_REQUIRE([gl_FUNC_FMODF])
+])
index cc0e666c0d94c9841fe5013bbe96dad5296653b9..812140d6f7211fa6f3dcc0e3055ffab50ab7b9f4 100644 (file)
@@ -1,4 +1,4 @@
-# fmodf.m4 serial 1
+# fmodf.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,7 @@ dnl with or without modifications, as long as this notice is preserved.
 
 AC_DEFUN([gl_FUNC_FMODF],
 [
+  m4_divert_text([DEFAULTS], [gl_fmodf_required=plain])
   AC_REQUIRE([gl_MATH_H_DEFAULTS])
   AC_REQUIRE([gl_FUNC_FMOD])
 
@@ -17,8 +18,57 @@ AC_DEFUN([gl_FUNC_FMODF],
   LIBS="$save_LIBS"
   if test $ac_cv_func_fmodf = yes; then
     FMODF_LIBM="$FMOD_LIBM"
+    m4_ifdef([gl_FUNC_FMODF_IEEE], [
+      if test $gl_fmodf_required = ieee && test $REPLACE_FMODF = 0; then
+        AC_CACHE_CHECK([whether fmodf works according to ISO C 99 with IEC 60559],
+          [gl_cv_func_fmodf_ieee],
+          [
+            save_LIBS="$LIBS"
+            LIBS="$LIBS $FMODF_LIBM"
+            AC_RUN_IFELSE(
+              [AC_LANG_SOURCE([[
+#ifndef __NO_MATH_INLINES
+# define __NO_MATH_INLINES 1 /* for glibc */
+#endif
+#include <math.h>
+/* 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 y) { return 0; }
+int main (int argc, char *argv[])
+{
+  float (*my_fmodf) (float, float) = argc ? fmodf : dummy;
+  float i;
+  float f;
+  /* Test fmodf(...,0.0f).
+     This test fails on OSF/1 5.1.  */
+  f = my_fmodf (2.0f, 0.0f);
+  if (numeric_equal (f, f))
+    return 1;
+  return 0;
+}
+              ]])],
+              [gl_cv_func_fmodf_ieee=yes],
+              [gl_cv_func_fmodf_ieee=no],
+              [gl_cv_func_fmodf_ieee="guessing no"])
+            LIBS="$save_LIBS"
+          ])
+        case "$gl_cv_func_fmodf_ieee" in
+          *yes) ;;
+          *) REPLACE_FMODF=1 ;;
+        esac
+      fi
+    ])
   else
     HAVE_FMODF=0
+  fi
+  if test $HAVE_FMODF = 0 || test $REPLACE_FMODF = 1; then
+    dnl Find libraries needed to link lib/fmodf.c.
     FMODF_LIBM="$FMOD_LIBM"
   fi
   AC_SUBST([FMODF_LIBM])
index 81c9da951331e5c61e679f4d5156531112f50786..34885e0a82876549ceed9e0930cad5b0e0f64ec7 100644 (file)
@@ -1,4 +1,4 @@
-# math_h.m4 serial 67
+# math_h.m4 serial 68
 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,
@@ -214,6 +214,7 @@ AC_DEFUN([gl_MATH_H_DEFAULTS],
   REPLACE_FMAF=0;              AC_SUBST([REPLACE_FMAF])
   REPLACE_FMAL=0;              AC_SUBST([REPLACE_FMAL])
   REPLACE_FMOD=0;              AC_SUBST([REPLACE_FMOD])
+  REPLACE_FMODF=0;             AC_SUBST([REPLACE_FMODF])
   REPLACE_FMODL=0;             AC_SUBST([REPLACE_FMODL])
   REPLACE_FREXPF=0;            AC_SUBST([REPLACE_FREXPF])
   REPLACE_FREXP=0;             AC_SUBST([REPLACE_FREXP])
index 705ce3b938d75f2344835a4f7531b881649b30b2..fa49437a64eea6e94aadc1e01cc0fc32bdd96041 100644 (file)
@@ -7,11 +7,11 @@ m4/fmodf.m4
 
 Depends-on:
 math
-fmod            [test $HAVE_FMODF = 0]
+fmod            [test $HAVE_FMODF = 0 || test $REPLACE_FMODF = 1]
 
 configure.ac:
 gl_FUNC_FMODF
-if test $HAVE_FMODF = 0; then
+if test $HAVE_FMODF = 0 || test $REPLACE_FMODF = 1; then
   AC_LIBOBJ([fmodf])
 fi
 gl_MATH_MODULE_INDICATOR([fmodf])
index 9569c9173f815eadc80b3521ec8a9171eb300d8f..b4e33b9458f4f9c0a11fbf7b108b4256a66171a1 100644 (file)
@@ -2,6 +2,7 @@ Description:
 fmodf() function according to ISO C 99 with IEC 60559.
 
 Files:
+m4/fmodf-ieee.m4
 
 Depends-on:
 fmodf
@@ -9,6 +10,7 @@ fpieee
 fmod-ieee       [test $HAVE_FMODF = 0]
 
 configure.ac:
+gl_FUNC_FMODF_IEEE
 
 Makefile.am:
 
index 8dd06253051bf598c44eb20c639a5c5abf434573..612aebedd972372ae5e041d2d7b578655b28b2b5 100644 (file)
@@ -183,6 +183,7 @@ math.h: math.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(
              -e 's|@''REPLACE_FMAF''@|$(REPLACE_FMAF)|g' \
              -e 's|@''REPLACE_FMAL''@|$(REPLACE_FMAL)|g' \
              -e 's|@''REPLACE_FMOD''@|$(REPLACE_FMOD)|g' \
+             -e 's|@''REPLACE_FMODF''@|$(REPLACE_FMODF)|g' \
              -e 's|@''REPLACE_FMODL''@|$(REPLACE_FMODL)|g' \
              -e 's|@''REPLACE_FREXPF''@|$(REPLACE_FREXPF)|g' \
              -e 's|@''REPLACE_FREXP''@|$(REPLACE_FREXP)|g' \