bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

modff math error reporting


From: Bruno Haible
Subject: modff math error reporting
Date: Mon, 27 Feb 2012 03:16:45 +0100
User-agent: KMail/4.7.4 (Linux/3.1.0-1.2-desktop; KDE/4.7.4; x86_64; ; )

> After I wrote NaN and Inf tests for the modf() function, the test-modf-ieee
> test fails on some platforms:

Similarly with the test-modff-ieee test:
Solaris 9      crash in call at line test-modf-ieee.h:25
Cygwin 1.7.9   test-modf-ieee.h:27: assertion failed
NetBSD 5.1     test-modf-ieee.h:27: assertion failed
OpenBSD 4.9    test-modf-ieee.h:27: assertion failed
IRIX 6.5       test-modf-ieee.h:35: assertion failed
mingw          test-modf-ieee.h:43: assertion failed
OSF/1 5.1      test-modf-ieee.h:43: assertion failed

Here's the workaround.


2012-02-26  Bruno Haible  <address@hidden>

        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.

============================== lib/modff-ieee.m4 ==============================
# 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])
])
===============================================================================
--- doc/posix-functions/modff.texi.orig Mon Feb 27 03:06:53 2012
+++ doc/posix-functions/modff.texi      Mon Feb 27 02:28:08 2012
@@ -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 @@
 MSVC 9.
 @end itemize
 
+Portability problems fixed by Gnulib module @code{modff-ieee}:
address@hidden
address@hidden
+This function has problems with a NaN argument on some platforms:
+NetBSD 5.1, OpenBSD 4.9, Solaris 9, Cygwin.
address@hidden
+This function has problems with infinite arguments on some platforms:
+IRIX 6.5, OSF/1 5.1, mingw.
address@hidden itemize
+
 Portability problems not fixed by Gnulib:
 @itemize
 @end itemize
--- lib/math.in.h.orig  Mon Feb 27 03:06:53 2012
+++ lib/math.in.h       Mon Feb 27 02:32:19 2012
@@ -866,11 +866,20 @@
 
 
 #if @GNULIB_MODFF@
-# if address@hidden@
-#  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 address@hidden@
+#   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
--- m4/math_h.m4.orig   Mon Feb 27 03:06:53 2012
+++ m4/math_h.m4        Mon Feb 27 02:32:42 2012
@@ -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 @@
   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])
--- m4/modff.m4.orig    Mon Feb 27 03:06:53 2012
+++ m4/modff.m4 Mon Feb 27 02:48:56 2012
@@ -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 @@
 
 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 @@
   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])
--- modules/math.orig   Mon Feb 27 03:06:53 2012
+++ modules/math        Mon Feb 27 02:33:03 2012
@@ -192,6 +192,7 @@
              -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' \
--- modules/modff.orig  Mon Feb 27 03:06:53 2012
+++ modules/modff       Mon Feb 27 02:39:14 2012
@@ -8,11 +8,11 @@
 
 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])
--- modules/modff-ieee.orig     Mon Feb 27 03:06:53 2012
+++ modules/modff-ieee  Mon Feb 27 02:50:46 2012
@@ -2,12 +2,17 @@
 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:
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]