public static LargeInt Multiply(LargeInt x, LargeInt y) { LargeInt newInt = new LargeInt(); for (int i = 0; i < y.Length; i++) { int carry = 0; for (int j = 0; j < x.Length; j++) { int zDigit = (y.GetDigitAt(i) * x.GetDigitAt(j)) + newInt.GetDigitAt(i + j) + carry; newInt.SetDigitAt(i + j, zDigit % 10); carry = zDigit / 10; } newInt.SetDigitAt(i + x.Length, carry); } return newInt; }
public static LargeInt Add(LargeInt x, LargeInt y) { int carry = 0; int loopLength = Math.Max(x.Length, y.Length) + 1; LargeInt newInt = new LargeInt(); for (int i = 0; i < loopLength; i++) { int xDigit = 0, yDigit = 0, zDigit = 0; xDigit = x.GetDigitAt(i); yDigit = y.GetDigitAt(i); zDigit = xDigit + yDigit + carry; if (zDigit >= radix) { zDigit %= radix; carry = 1; } else { carry = 0; } newInt.SetDigitAt(i, zDigit); } return newInt; }