OSDN Git Service

PR libfortran/47970
[pf3gnuchains/gcc-fork.git] / libgfortran / intrinsics / c99_functions.c
index 03bcbfe..a95f09a 100644 (file)
@@ -1,5 +1,5 @@
 /* Implementation of various C99 functions 
-   Copyright (C) 2004, 2009 Free Software Foundation, Inc.
+   Copyright (C) 2004, 2009, 2010 Free Software Foundation, Inc.
 
 This file is part of the GNU Fortran 95 runtime library (libgfortran).
 
@@ -558,7 +558,37 @@ powf (float x, float y)
 }
 #endif
 
-/* Note that if fpclassify is not defined, then NaN is not handled */
+
+#ifndef HAVE_ROUND
+#define HAVE_ROUND 1
+/* Round to nearest integral value.  If the argument is halfway between two
+   integral values then round away from zero.  */
+double round (double x);
+
+double
+round (double x)
+{
+   double t;
+   if (!isfinite (x))
+     return (x);
+
+   if (x >= 0.0) 
+    {
+      t = floor (x);
+      if (t - x <= -0.5)
+       t += 1.0;
+      return (t);
+    } 
+   else 
+    {
+      t = floor (-x);
+      if (t + x <= -0.5)
+       t += 1.0;
+      return (-t);
+    }
+}
+#endif
+
 
 /* Algorithm by Steven G. Kargl.  */
 
@@ -601,7 +631,7 @@ roundl (long double x)
   if (x > DBL_MAX || x < -DBL_MAX)
     {
 #ifdef HAVE_NEXTAFTERL
-      static long double prechalf = nexafterl (0.5L, LDBL_MAX);
+      long double prechalf = nextafterl (0.5L, LDBL_MAX);
 #else
       static long double prechalf = 0.5L;
 #endif
@@ -615,36 +645,6 @@ roundl (long double x)
 #endif
 #endif
 
-#ifndef HAVE_ROUND
-#define HAVE_ROUND 1
-/* Round to nearest integral value.  If the argument is halfway between two
-   integral values then round away from zero.  */
-double round (double x);
-
-double
-round (double x)
-{
-   double t;
-   if (!isfinite (x))
-     return (x);
-
-   if (x >= 0.0) 
-    {
-      t = floor (x);
-      if (t - x <= -0.5)
-       t += 1.0;
-      return (t);
-    } 
-   else 
-    {
-      t = floor (-x);
-      if (t + x <= -0.5)
-       t += 1.0;
-      return (-t);
-    }
-}
-#endif
-
 #ifndef HAVE_ROUNDF
 #define HAVE_ROUNDF 1
 /* Round to nearest integral value.  If the argument is halfway between two
@@ -1854,7 +1854,7 @@ tgamma (double x)
   n = 0;
   y = x;
 
-  if (__builtin_isnan (x))
+  if (isnan (x))
     return x;
 
   if (y <= 0)