2002-06-08 Martin Baulig <martin@gnome.org>
[mono.git] / mcs / class / corlib / System / Math.cs
index f4a0e70d76ab5e08a4df9c2bf1dd5efc831d709a..b38a67666790ae6e725de3f63b8d39977bbdc050 100644 (file)
@@ -62,11 +62,35 @@ namespace System
 
                 public static double Ceiling(double a)
                 {
-                        double b = (double)((long)a);
+                       if (Double.IsNaN(a)){
+                               return Double.NaN;
+                       }
+
+                       if (Double.IsNegativeInfinity(a)){
+                               return Double.NegativeInfinity;
+                       }
+
+                       if (Double.IsPositiveInfinity(a)){
+                               return Double.PositiveInfinity;
+                       }
+
+                       double b = (double)((long)a);
                         return (b < a)? b+1: b;
                 }
                 public static double Floor(double d) {
-                        double b = (double)((long)d);
+                       if (Double.IsNaN(d)){
+                               return Double.NaN;
+                       }
+
+                       if (Double.IsNegativeInfinity(d)){
+                               return Double.NegativeInfinity;
+                       }
+
+                       if (Double.IsPositiveInfinity(d)){
+                               return Double.PositiveInfinity;
+                       }
+
+                       double b = (double)((long)d);
                        return (d < 0 && d != b) ? --b : b;
                 }
                 public static double IEEERemainder(double x, double y)
@@ -203,7 +227,7 @@ namespace System
                 }
                 public static decimal Round(decimal d, int decimals)
                 {
-                        long p = 10;
+                        long p = 1;
                         int c;
                         decimal retval = d;
                         if (decimals < 0 || decimals > 15)
@@ -230,7 +254,7 @@ namespace System
                         }
                 }
                 public static double Round(double value, int digits) {
-                        long p = 10;
+                        long p = 1;
                         int c;
                         double retval = value;
                         if (digits < 0 || digits > 15)
@@ -323,8 +347,27 @@ namespace System
                [MethodImplAttribute (MethodImplOptions.InternalCall)]
                 public extern static double Log10 (double x);
 
+               public static double Pow (double x, double y) {
+                       if (Double.IsNaN (x) || Double.IsNaN (y))
+                               return Double.NaN;
+                       if (Double.IsNegativeInfinity (x))
+                               if (((int)y & 1) == 1)
+                                       return Double.NegativeInfinity;
+                               else
+                                       return Double.PositiveInfinity;
+                       if (Double.IsPositiveInfinity (x))
+                               if (Double.IsNegativeInfinity (y))
+                                       return 0;
+                               else
+                                       return Double.PositiveInfinity;
+                       if (Double.IsNegativeInfinity (y) || Double.IsPositiveInfinity (y))
+                               return Double.NaN;
+                       
+                       return PowImpl (x, y);
+               }
+
                [MethodImplAttribute (MethodImplOptions.InternalCall)]
-                public extern static double Pow (double x, double y);
+                public extern static double PowImpl (double x, double y);
 
                [MethodImplAttribute (MethodImplOptions.InternalCall)]
                 public extern static double Sqrt (double x);