modfl-ieee: Fix test failures.
[gnulib.git] / lib / modfl.c
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