Beispiel #1
0
        public void Add(BigInt big)
        {
            //add stacks
            this.stackCount = this.stackCount + big.stackCount;

            //add current
            Add(big.current);
        }
Beispiel #2
0
        public void Multiply(BigInt big)
        {
            //(a + x) * (b + y) = a*b + a*y + x*b + x*y;

            //multiply stacks (a*b)
            int newStack = this.stackCount * big.stackCount;

            //stack * current of big (a*y)
            newStack = newStack + this.stackCount * big.current;

            //stack of big * this current (x*b)
            newStack = newStack + big.stackCount * this.current;

            //x*y
            BigInt x_y = IntMultiply(this.current, big.current);
            this.Add(x_y);
        }
Beispiel #3
0
        public static void Test()
        {
            //Console.WriteLine(int.MaxValue);

            BigInt bigA = new BigInt();
            BigInt bigB = new BigInt();

            //1000000000
            //999999999
            //11000000000
            bigA.Add(500000000);
            bigB.Add(888888888);

            bigA.Multiply(bigB);

            Console.WriteLine(bigA);

            //int x = -22;
            //Console.WriteLine(x % 4);
        }
Beispiel #4
0
        private BigInt IntMultiply(int a, int b)
        {
            BigInt result = new BigInt();

            for (int i = 0; i < b; i++)
            {
                result.Add(a);
            }

            return result;
        }