2010-03-04 Rodrigo Kumpera <rkumpera@novell.com>
authorRodrigo Kumpera <kumpera@gmail.com>
Fri, 5 Mar 2010 03:33:26 +0000 (03:33 -0000)
committerRodrigo Kumpera <kumpera@gmail.com>
Fri, 5 Mar 2010 03:33:26 +0000 (03:33 -0000)
* BigInteger.cs: Add constructor and coersion operators
for ulong.

svn path=/trunk/mcs/; revision=153077

mcs/class/System.Numerics/System.Numerics/BigInteger.cs
mcs/class/System.Numerics/System.Numerics/ChangeLog

index 89f30a29e455f369a42214b59145ca34bd19f2ae..59fd064ef60e07362fb77c9405808521dda5c423 100644 (file)
@@ -116,6 +116,24 @@ namespace System.Numerics {
                        }                       
                }
 
+               [CLSCompliantAttribute (false)]
+               public BigInteger (ulong value)
+               {
+                       if (value == 0) {
+                               sign = 0;
+                               data = ZERO;
+                       } else {
+                               sign = 1;
+                               uint low = (uint)value;
+                               uint high = (uint)(value >> 32);
+
+                               data = new uint [high != 0 ? 2 : 1];
+                               data [0] = low;
+                               if (high != 0)
+                                       data [1] = high;
+                       }
+               }
+
                public BigInteger (byte[] value)
                {
                        if (value == null)
@@ -327,6 +345,21 @@ namespace System.Numerics {
                        return - ((((long)high) << 32) | (long)low);
                }
 
+               [CLSCompliantAttribute (false)]
+               public static explicit operator ulong (BigInteger value)
+               {
+                       if (value.data.Length > 2 || value.sign == -1)
+                               throw new OverflowException ();
+
+                       uint low = value.data [0];
+                       if (value.data.Length == 1)
+                               return low;
+
+                       uint high = value.data [1];
+                       return (((ulong)high) << 32) | low;
+               }
+
+
                public static implicit operator BigInteger (int value)
                {
                        return new BigInteger (value);
@@ -338,12 +371,16 @@ namespace System.Numerics {
                        return new BigInteger (value);
                }
 
-
                public static implicit operator BigInteger (long value)
                {
                        return new BigInteger (value);
                }
 
+               public static implicit operator BigInteger (ulong value)
+               {
+                       return new BigInteger (value);
+               }
+
                public static BigInteger operator+ (BigInteger left, BigInteger right)
                {
                        if (left.sign == 0)
index 6d4515c5b85235a873e2e24b9c83db180e352b9e..41e17147ddeb64d9a95ccd2821d8ce4b5979062f 100644 (file)
@@ -1,3 +1,8 @@
+2010-03-04 Rodrigo Kumpera  <rkumpera@novell.com>
+
+       * BigInteger.cs: Add constructor and coersion operators
+       for ulong.
+
 2010-03-04 Rodrigo Kumpera  <rkumpera@novell.com>
 
        * BigInteger.cs: Add constructor and coersion operators