modfl-ieee: Fix test failures.
authorBruno Haible <bruno@clisp.org>
Mon, 27 Feb 2012 03:03:02 +0000 (04:03 +0100)
committerBruno Haible <bruno@clisp.org>
Mon, 27 Feb 2012 03:03:02 +0000 (04:03 +0100)
* lib/modfl.c (modfl): Treat NaN and Inf specially.
* modules/modfl (Depends-on): Add isfinite, isinf.

ChangeLog
lib/modfl.c
modules/modfl

index 3e0fc21..764a1a0 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2012-02-26  Bruno Haible  <bruno@clisp.org>
 
+       modfl-ieee: Fix test failures.
+       * lib/modfl.c (modfl): Treat NaN and Inf specially.
+       * modules/modfl (Depends-on): Add isfinite, isinf.
+
        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
index 770294b..65e3246 100644 (file)
@@ -35,9 +35,25 @@ modfl (long double x, long double *iptr)
 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
index 0c6f53b..3456a4c 100644 (file)
@@ -9,7 +9,9 @@ m4/mathfunc.m4
 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