md5, sha1, sha256, sha512: add gl_SET_CRYPTO_CHECK_DEFAULT
[gnulib.git] / lib / modfl.c
index 770294b..41ba10c 100644 (file)
@@ -1,5 +1,5 @@
 /* Get signed integer and fractional parts of a floating-point number.
-   Copyright (C) 2012 Free Software Foundation, Inc.
+   Copyright (C) 2012-2013 Free Software Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -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