fmodl-ieee: Fix test failures.
authorBruno Haible <bruno@clisp.org>
Mon, 27 Feb 2012 10:35:41 +0000 (11:35 +0100)
committerBruno Haible <bruno@clisp.org>
Mon, 27 Feb 2012 10:35:41 +0000 (11:35 +0100)
* lib/fmodl.c (fmodl): Treat Inf specially.
* modules/fmodl (Depends-on): Add isinf.

ChangeLog
lib/fmodl.c
modules/fmodl

index dc0b33b..37d52ed 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2012-02-27  Bruno Haible  <bruno@clisp.org>
 
+       fmodl-ieee: Fix test failures.
+       * lib/fmodl.c (fmodl): Treat Inf specially.
+       * modules/fmodl (Depends-on): Add isinf.
+
        Tests for module 'fmodl-ieee'.
        * modules/fmodl-ieee-tests: New file.
        * tests/test-fmodl-ieee.c: New file.
index a7ccd8b..8ddd62b 100644 (file)
@@ -32,48 +32,53 @@ fmodl (long double x, long double y)
 long double
 fmodl (long double x, long double y)
 {
-  long double q = - truncl (x / y);
-  long double r = fmal (q, y, x); /* = x + q * y, computed in one step */
-  /* Correct possible rounding errors in the quotient x / y.  */
-  if (y >= 0)
-    {
-      if (x >= 0)
-        {
-          /* Expect 0 <= r < y.  */
-          if (r < 0)
-            q += 1, r = fmal (q, y, x);
-          else if (r >= y)
-            q -= 1, r = fmal (q, y, x);
-        }
-      else
-        {
-          /* Expect - y < r <= 0.  */
-          if (r > 0)
-            q -= 1, r = fmal (q, y, x);
-          else if (r <= - y)
-            q += 1, r = fmal (q, y, x);
-        }
-    }
+  if (isinf (y))
+    return x;
   else
     {
-      if (x >= 0)
+      long double q = - truncl (x / y);
+      long double r = fmal (q, y, x); /* = x + q * y, computed in one step */
+      /* Correct possible rounding errors in the quotient x / y.  */
+      if (y >= 0)
         {
-          /* Expect 0 <= r < - y.  */
-          if (r < 0)
-            q -= 1, r = fmal (q, y, x);
-          else if (r >= - y)
-            q += 1, r = fmal (q, y, x);
+          if (x >= 0)
+            {
+              /* Expect 0 <= r < y.  */
+              if (r < 0)
+                q += 1, r = fmal (q, y, x);
+              else if (r >= y)
+                q -= 1, r = fmal (q, y, x);
+            }
+          else
+            {
+              /* Expect - y < r <= 0.  */
+              if (r > 0)
+                q -= 1, r = fmal (q, y, x);
+              else if (r <= - y)
+                q += 1, r = fmal (q, y, x);
+            }
         }
       else
         {
-          /* Expect y < r <= 0.  */
-          if (r > 0)
-            q += 1, r = fmal (q, y, x);
-          else if (r <= y)
-            q -= 1, r = fmal (q, y, x);
+          if (x >= 0)
+            {
+              /* Expect 0 <= r < - y.  */
+              if (r < 0)
+                q -= 1, r = fmal (q, y, x);
+              else if (r >= - y)
+                q += 1, r = fmal (q, y, x);
+            }
+          else
+            {
+              /* Expect y < r <= 0.  */
+              if (r > 0)
+                q += 1, r = fmal (q, y, x);
+              else if (r <= y)
+                q -= 1, r = fmal (q, y, x);
+            }
         }
+      return r;
     }
-  return r;
 }
 
 #endif
index 29b5843..bf192ee 100644 (file)
@@ -9,6 +9,7 @@ m4/mathfunc.m4
 Depends-on:
 math
 fmod            [{ test $HAVE_FMODL = 0 || test $REPLACE_FMODL = 1; } && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1]
+isinf           [{ test $HAVE_FMODL = 0 || test $REPLACE_FMODL = 1; } && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 0]
 truncl          [{ test $HAVE_FMODL = 0 || test $REPLACE_FMODL = 1; } && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 0]
 fmal            [{ test $HAVE_FMODL = 0 || test $REPLACE_FMODL = 1; } && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 0]