Add new block cursor helper properties, start implementation of StakeModifier calcula...
[NovacoinLibrary.git] / Novacoin / base_uint.cs
index 072111f..8b36b12 100644 (file)
@@ -28,31 +28,43 @@ namespace Novacoin
     /// </summary>
     public class base_uint : IComparable<base_uint>, IEquatable<base_uint>, IEqualityComparer<base_uint>
     {
+        #region Internal representation
+        /// <summary>
+        /// Length of internal representation
+        /// </summary>
         protected int nWidth;
+        /// <summary>
+        /// Big numbers are stored as array of unsigned 32-bit integers.
+        /// </summary>
         protected uint[] pn;
+        #endregion
 
-        public double getDouble()
+        #region Helper properties
+        public double Double
         {
-            double ret = 0.0;
-            double fact = 1.0;
-
-            for (int i = 0; i < nWidth; i++)
+            get
             {
-                ret += fact * pn[i];
-                fact *= 4294967296.0;
-            }
+                double ret = 0.0;
+                double fact = 1.0;
+
+                for (int i = 0; i < nWidth; i++)
+                {
+                    ret += fact * pn[i];
+                    fact *= 4294967296.0;
+                }
 
-            return ret;
+                return ret;
+            }
         }
 
-        public ulong GetLow64()
+        public ulong Low64
         {
-            return pn[0] | (ulong)pn[1] << 32;
+            get { return pn[0] | (ulong)pn[1] << 32; }
         }
 
-        public uint GetLow32()
+        public uint Low32
         {
-            return pn[0];
+            get { return pn[0]; }
         }
 
         /// <summary>
@@ -75,11 +87,11 @@ namespace Novacoin
             {
                 for (int pos = nWidth - 1; pos >= 0; pos--)
                 {
-                    if (pn[pos]!=0)
+                    if (pn[pos] != 0)
                     {
                         for (int bits = 31; bits > 0; bits--)
                         {
-                            if ((pn[pos] & 1 << bits)!=0)
+                            if ((pn[pos] & 1 << bits) != 0)
                                 return 32 * pos + bits + 1;
                         }
                         return 32 * pos + 1;
@@ -88,7 +100,14 @@ namespace Novacoin
                 return 0;
             }
         }
+        #endregion
+
 
+        /// <summary>
+        /// Negation operator
+        /// </summary>
+        /// <param name="a">Value</param>
+        /// <returns>True if value is zero, false otherwise.</returns>
         public static bool operator !(base_uint a)
         {
             for (int i = 0; i < a.nWidth; i++)
@@ -219,7 +238,7 @@ namespace Novacoin
         }
         #endregion
 
-        #region Cast oerations
+        #region Cast operations
         /// <summary>
         /// True cast operator
         /// </summary>
@@ -250,6 +269,12 @@ namespace Novacoin
         }
         #endregion
 
+        /// <summary>
+        /// Arrays equality checking helper method.
+        /// </summary>
+        /// <param name="a">Array 1</param>
+        /// <param name="b">Array 2</param>
+        /// <returns>Result.</returns>
         private static bool ArraysEqual(uint[] a, uint[] b)
         {
             Contract.Requires<ArgumentException>(a.Length == b.Length, "Array length mismatch.");
@@ -302,7 +327,7 @@ namespace Novacoin
         #region IEquatable
         public bool Equals(base_uint a)
         {
-            if (a == null)
+            if (object.ReferenceEquals(a, null))
             {
                 return false;
             }
@@ -329,6 +354,10 @@ namespace Novacoin
         }
         #endregion
 
+        /// <summary>
+        /// Serialize to string.
+        /// </summary>
+        /// <returns></returns>
         public override string ToString()
         {
             return Interop.ToHex(Interop.ReverseBytes(this));