Author: jbevain
Date: 2006-06-20 16:27:57 -0400 (Tue, 20 Jun 2006)
New Revision: 61884

Modified:
   trunk/mcs/class/corlib/System/ChangeLog
   trunk/mcs/class/corlib/System/Math.cs
   trunk/mcs/class/corlib/Test/System/ChangeLog
   trunk/mcs/class/corlib/Test/System/MathTest.cs
Log:
2006-06-20  Jb Evain  <[EMAIL PROTECTED]>

        * Math.cs: implement Math.Truncate.


Modified: trunk/mcs/class/corlib/System/ChangeLog
===================================================================
--- trunk/mcs/class/corlib/System/ChangeLog     2006-06-20 19:09:41 UTC (rev 
61883)
+++ trunk/mcs/class/corlib/System/ChangeLog     2006-06-20 20:27:57 UTC (rev 
61884)
@@ -1,3 +1,7 @@
+2006-06-20  Jb Evain  <[EMAIL PROTECTED]>
+
+       * Math.cs: implement Math.Truncate.
+
 2006-06-13  Atsushi Enomoto  <[EMAIL PROTECTED]>
 
        * DateTime.cs :

Modified: trunk/mcs/class/corlib/System/Math.cs
===================================================================
--- trunk/mcs/class/corlib/System/Math.cs       2006-06-20 19:09:41 UTC (rev 
61883)
+++ trunk/mcs/class/corlib/System/Math.cs       2006-06-20 20:27:57 UTC (rev 
61884)
@@ -421,6 +421,21 @@
                                return Round (value, digits);
                        throw new NotImplementedException ();
                }
+
+               public static double Truncate (double d)
+               {
+                       if (d > 0D)
+                               return Floor (d);
+                       else if (d < 0D)
+                               return Ceiling (d);
+                       else
+                               return d;
+               }
+
+               public static decimal Truncate (decimal d)
+               {
+                       return Decimal.Truncate (d);
+               }
 #endif
 
                public static int Sign (decimal value)

Modified: trunk/mcs/class/corlib/Test/System/ChangeLog
===================================================================
--- trunk/mcs/class/corlib/Test/System/ChangeLog        2006-06-20 19:09:41 UTC 
(rev 61883)
+++ trunk/mcs/class/corlib/Test/System/ChangeLog        2006-06-20 20:27:57 UTC 
(rev 61884)
@@ -1,3 +1,7 @@
+2006-06-20  Jb Evain  <[EMAIL PROTECTED]>
+
+       * MathTest.cs: add tests for Math.Truncate.
+
 2006-05-08  Atsushi Enomoto  <[EMAIL PROTECTED]>
 
        * ArrayTest.cs : test for bug #77277 by Kazuki Oikawa.

Modified: trunk/mcs/class/corlib/Test/System/MathTest.cs
===================================================================
--- trunk/mcs/class/corlib/Test/System/MathTest.cs      2006-06-20 19:09:41 UTC 
(rev 61883)
+++ trunk/mcs/class/corlib/Test/System/MathTest.cs      2006-06-20 20:27:57 UTC 
(rev 61884)
@@ -706,6 +706,44 @@
                Assert(Double.MinValue == Math.Round(Double.MinValue));
        }
 
+#if NET_2_0
+       public void TestDoubleTruncate ()
+       {
+               double a = 1.2D;
+               double b = 2.8D;
+               double c = 0D;
+
+               AssertEquals ("Should truncate to 1", Math.Truncate (a), 1D);
+               AssertEquals ("Should truncate to 2", Math.Truncate (b), 2D);
+
+               AssertEquals ("Should truncate to -1", Math.Truncate (a * -1D), 
-1D);
+               AssertEquals ("Should truncate to -2", Math.Truncate (b * -1D), 
-2D);
+
+               AssertEquals ("Should return 0", Math.Truncate (c), 0D);
+
+               Assert (Double.MaxValue == Math.Truncate (Double.MaxValue));
+               Assert (Double.MinValue == Math.Truncate (Double.MinValue));
+       }
+
+       public void TestDecimalTruncate ()
+       {
+               decimal a = 1.2M;
+               decimal b = 2.8M;
+               decimal c = 0M;
+
+               AssertEquals ("Should truncate to 1", Math.Truncate (a), 1M);
+               AssertEquals ("Should truncate to 2", Math.Truncate (b), 2M);
+
+               AssertEquals ("Should truncate to -1", Math.Truncate (a * -1M), 
-1M);
+               AssertEquals ("Should truncate to -2", Math.Truncate (b * -1M), 
-2M);
+
+               AssertEquals ("Should return 0", Math.Truncate (c), 0M);
+
+               Assert (Decimal.MaxValue == Math.Truncate (Decimal.MaxValue));
+               Assert (Decimal.MinValue == Math.Truncate (Decimal.MinValue));
+       }
+#endif
+
        public void TestDoubleRound2() {
                double a = 3.45D;
                double b = 3.46D;

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to