changeset 16488:8bed60fd8e6c

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.
author Bruno Haible <bruno@clisp.org>
date Mon, 27 Feb 2012 13:18:57 +0100
parents 3e8b04abbb58
children 36e7fba2448d
files ChangeLog doc/posix-functions/fmodf.texi lib/math.in.h m4/fmodf-ieee.m4 m4/fmodf.m4 m4/math_h.m4 modules/fmodf modules/fmodf-ieee modules/math
diffstat 9 files changed, 101 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- 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.
--- a/doc/posix-functions/fmodf.texi
+++ b/doc/posix-functions/fmodf.texi
@@ -19,6 +19,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.
--- a/lib/math.in.h
+++ b/lib/math.in.h
@@ -615,11 +615,20 @@
 
 
 #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
+_GL_CXXALIAS_SYS (fmodf, float, (float x, float y));
 # endif
-_GL_CXXALIAS_SYS (fmodf, float, (float x, float y));
 _GL_CXXALIASWARN (fmodf);
 #elif defined GNULIB_POSIXCHECK
 # undef fmodf
new file mode 100644
--- /dev/null
+++ b/m4/fmodf-ieee.m4
@@ -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])
+])
--- a/m4/fmodf.m4
+++ b/m4/fmodf.m4
@@ -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 @@
 
 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 @@
   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])
--- a/m4/math_h.m4
+++ b/m4/math_h.m4
@@ -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 @@
   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])
--- a/modules/fmodf
+++ b/modules/fmodf
@@ -7,11 +7,11 @@
 
 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])
--- a/modules/fmodf-ieee
+++ b/modules/fmodf-ieee
@@ -2,6 +2,7 @@
 fmodf() function according to ISO C 99 with IEC 60559.
 
 Files:
+m4/fmodf-ieee.m4
 
 Depends-on:
 fmodf
@@ -9,6 +10,7 @@
 fmod-ieee       [test $HAVE_FMODF = 0]
 
 configure.ac:
+gl_FUNC_FMODF_IEEE
 
 Makefile.am:
 
--- a/modules/math
+++ b/modules/math
@@ -183,6 +183,7 @@
 	      -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' \