Use signed 64 bit integers for better compatibility.
[NovacoinLibrary.git] / Novacoin / BigNum.cs
index af8ae4a..9e49922 100644 (file)
@@ -34,6 +34,11 @@ namespace Novacoin
             bn = new BigInteger(BitConverter.GetBytes(ulongValue));
         }
 
+        public BigNum(long longValue)
+        {
+            bn = new BigInteger(Math.Sign(longValue), BitConverter.GetBytes(longValue));
+        }
+
         public BigNum(uint256 uint256Value)
         {
             bn = new BigInteger(uint256Value);
@@ -47,11 +52,22 @@ namespace Novacoin
             return new BigNum(a.bn.Add(bnValueToAdd));
         }
 
+        public static BigNum operator +(BigNum a, long b)
+        {
+            var bnValueToAdd = new BigInteger(BitConverter.GetBytes(b));
+            return new BigNum(a.bn.Add(bnValueToAdd));
+        }
+
         public static BigNum operator -(BigNum a, ulong b)
         {
             var bnValueToSubstract = new BigInteger(BitConverter.GetBytes(b));
             return new BigNum(a.bn.Subtract(bnValueToSubstract));
         }
+        public static BigNum operator -(BigNum a, long b)
+        {
+            var bnValueToSubstract = new BigInteger(BitConverter.GetBytes(b));
+            return new BigNum(a.bn.Subtract(bnValueToSubstract));
+        }
 
         public static BigNum operator +(BigNum a, uint256 b)
         {
@@ -81,6 +97,12 @@ namespace Novacoin
             return new BigNum(a.bn.Divide(bnDivider));
         }
 
+        public static BigNum operator /(BigNum a, long b)
+        {
+            var bnDivider = new BigInteger(BitConverter.GetBytes(b));
+            return new BigNum(a.bn.Divide(bnDivider));
+        }
+
         public static BigNum operator /(BigNum a, uint256 b)
         {
             var bnDivider = new BigInteger(b);
@@ -98,6 +120,12 @@ namespace Novacoin
             return new BigNum(a.bn.Multiply(bnMultiplier));
         }
 
+        public static BigNum operator *(BigNum a, long b)
+        {
+            var bnMultiplier = new BigInteger(BitConverter.GetBytes(b));
+            return new BigNum(a.bn.Multiply(bnMultiplier));
+        }
+
         public static BigNum operator *(BigNum a, uint256 b)
         {
             var bnMultiplier = new BigInteger(b);
@@ -153,6 +181,11 @@ namespace Novacoin
             return new BigNum(ulongValue);
         }
 
+        public static implicit operator BigNum(long ulongValue)
+        {
+            return new BigNum(ulongValue);
+        }
+
         public static implicit operator BigNum(uint256 uint256Value)
         {
             return new BigNum(uint256Value);
@@ -163,6 +196,11 @@ namespace Novacoin
             return (ulong)a.bn.LongValue;
         }
 
+        public static implicit operator long (BigNum a)
+        {
+            return a.bn.LongValue;
+        }
+
         public int CompareTo(BigNum other)
         {
             return bn.CompareTo(other.bn);