bug-gnulib
[Top][All Lists]
Advanced

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

modfl math error reporting


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

The test-modfl-ieee test also fails. The gnulib replacement code is one of
the culprits, and other than that:

IRIX 6.5    test-modf-ieee.h:35: assertion failed
OSF/1 5.1   test-modf-ieee.h:43: assertion failed
mingw       test-modf-ieee.h:43: assertion failed

Three fixes make it all work.


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

        modfl-ieee: Fix test failures.
        * lib/modfl.c (modfl): Treat NaN and Inf specially.
        * modules/modfl (Depends-on): Add isfinite, isinf.

--- lib/modfl.c.orig    Mon Feb 27 04:00:44 2012
+++ lib/modfl.c Mon Feb 27 00:07:09 2012
@@ -35,9 +35,25 @@
 long double
 modfl (long double x, long double *iptr)
 {
-  long double integer_part = truncl (x);
-  *iptr = integer_part;
-  return x - integer_part;
+  if (isfinite (x))
+    {
+      long double integer_part = truncl (x);
+      *iptr = integer_part;
+      return x - integer_part;
+    }
+  else
+    {
+      if (isinf (x))
+        {
+          *iptr = x;
+          return 1.0L / x;
+        }
+      else /* isnanl (x) */
+        {
+          *iptr = x;
+          return x;
+        }
+    }
 }
 
 #endif
--- modules/modfl.orig  Mon Feb 27 04:00:44 2012
+++ modules/modfl       Mon Feb 27 00:08:13 2012
@@ -9,7 +9,9 @@
 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]
 
 configure.ac:
 gl_FUNC_MODFL



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

        modfl-ieee: Fix dependencies.
        * modules/modfl-ieee (Depends-on): Add modf-ieee.

--- modules/modfl-ieee.orig     Mon Feb 27 04:00:44 2012
+++ modules/modfl-ieee  Mon Feb 27 03:59:27 2012
@@ -6,6 +6,7 @@
 Depends-on:
 modfl
 fpieee
+modf-ieee       [test $HAVE_MODFL = 0 && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE 
= 1]
 
 configure.ac:
 


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

        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.

============================== m4/modfl-ieee.m4 ==============================
# 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])
])
==============================================================================
--- doc/posix-functions/modfl.texi.orig Mon Feb 27 04:57:57 2012
+++ doc/posix-functions/modfl.texi      Mon Feb 27 04:08:58 2012
@@ -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}:
address@hidden
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 04:57:57 2012
+++ lib/math.in.h       Mon Feb 27 04:10:10 2012
@@ -910,12 +910,22 @@
 #endif
 
 #if @GNULIB_MODFL@
-# if address@hidden@
-#  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 address@hidden@
+#   undef modfl
 _GL_FUNCDECL_SYS (modfl, long double, (long double x, long double *iptr)
                                       _GL_ARG_NONNULL ((2)));
-# endif
+#  endif
 _GL_CXXALIAS_SYS (modfl, long double, (long double x, long double *iptr));
+# endif
 _GL_CXXALIASWARN (modfl);
 #elif defined GNULIB_POSIXCHECK
 # undef modfl
--- m4/math_h.m4.orig   Mon Feb 27 04:57:57 2012
+++ m4/math_h.m4        Mon Feb 27 04:12:04 2012
@@ -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])
--- m4/modfl.m4.orig    Mon Feb 27 04:57:57 2012
+++ m4/modfl.m4 Mon Feb 27 04:17:14 2012
@@ -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"
--- modules/math.orig   Mon Feb 27 04:57:57 2012
+++ modules/math        Mon Feb 27 04:12:22 2012
@@ -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' \
--- modules/modfl.orig  Mon Feb 27 04:57:57 2012
+++ modules/modfl       Mon Feb 27 04:18:56 2012
@@ -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])
--- modules/modfl-ieee.orig     Mon Feb 27 04:57:57 2012
+++ modules/modfl-ieee  Mon Feb 27 04:17:53 2012
@@ -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:
 




reply via email to

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