public static void Main(string[] args) { Console.WriteLine("Hello World!"); clsBigInt A = new clsBigInt("-1232134"); clsBigInt B = new clsBigInt("-435789634583749"); if (A == B) { Console.WriteLine("A is: {0} == B: {1}", A.Value, B.Value); } else if (A > B) { Console.WriteLine("A is: {0} > B: {1}", A.Value, B.Value); } else { Console.WriteLine("A is: {0} < B: {1}", A.Value, B.Value); } clsBigInt C = A + B; Console.WriteLine("A is: {0} + B: {1} = C: {2}", A.Value, B.Value, C.Value); //Console.WriteLine("A is: {0} have ABS: {1}", A.Value, A.ABS().Value); Console.Write("Press any key to continue . . . "); Console.ReadKey(true); }
public clsBigInt ABS() { clsBigInt result = new clsBigInt(); if (IsMinus()) { result.Value = Value.Substring(1, Value.Length - 1); } else { result.Value = Value; } return(result); }
public clsBigInt(clsBigInt bigInt) { this.Value = bigInt.Value; }
public static clsBigInt operator -(clsBigInt A, clsBigInt B) { clsBigInt C = new clsBigInt(); return(C); }
public static clsBigInt operator +(clsBigInt A, clsBigInt B) { int iLength = 0, iA, iB, iC, iMemory; clsBigInt C = new clsBigInt(); string sTemp = ""; if (A.IsMinus() == false && B.IsMinus() == false) { if (A.Value.Length > B.Value.Length) { iLength = A.Value.Length; } else { iLength = B.Value.Length; } iMemory = 0; for (int i = 0; i < iLength; i++) { if (i < A.Value.Length) { iA = int.Parse(A.Value.Substring(A.Value.Length - i - 1, 1)); } else { iA = 0; } if (i < B.Value.Length) { iB = int.Parse(B.Value.Substring(B.Value.Length - i - 1, 1)); } else { iB = 0; } iC = iA + iB + iMemory; if (iC > 10) { sTemp = string.Format("{0}", iC % 10) + sTemp; iMemory = 1; } else { sTemp = string.Format("{0}", iC % 10) + sTemp; iMemory = 0; } C.Value = sTemp; } } else if (A.IsMinus() == true && B.IsMinus() == true) { clsBigInt D = A.ABS() + B.ABS(); C.Value = "-" + D.Value; } else if (A.IsMinus() == false && B.IsMinus() == true) { C = A - B.ABS(); } else if (A.IsMinus() == true && B.IsMinus() == false) { C = B - A.ABS(); } return(C); }