Exemple #1
0
 public LargeInt(LargeInt initialValue)
 {
     for (int i = 0; i < initialValue.Length; i++)
     {
         SetDigitAt(i, initialValue.GetDigitAt(i));
     }
 }
Exemple #2
0
        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;
        }
Exemple #3
0
        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;
        }