示例#1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            Huge h1 = new Huge(123456789);

            Console.WriteLine(h1);
            Huge h2 = new Huge("8888888888888888888888");
            Huge h3 = new Huge("8888888888888888888888");

            Console.WriteLine(h2);
            Console.WriteLine(h3);
            Huge sum = h2 + h3;

            Console.WriteLine(sum);

            //Huge product = h2 * h3;

            //Console.WriteLine(product);

            //Huge h4 = h2 + 1234567;

            //Huge h5 = h1.Power(10);

            //Console.WriteLine(h5);
        }
示例#2
0
        static void Main(string[] args)
        {
            Huge h1 = new Huge(123456789);

            Console.WriteLine(h1);
            Huge h2 = new Huge("8888");
            Huge h3 = new Huge("8888");

            Console.WriteLine(h2);
            Console.WriteLine(h3);
            Huge sum = h2 + h3;

            Console.WriteLine(sum);

            Huge product = h2 * h3;

            Console.WriteLine("produsul este :");
            Console.WriteLine(product);

            //Huge h4 = h2 + 1234567;

            //Huge h5 = h1.Power(10);

            //Console.WriteLine(h5);

            //int mod = h4 % 1234564;

            // Console.WriteLine(h5);

            //BigInteger big = new BigInteger();
        }
示例#3
0
        public static Huge operator+(Huge left, Huge right)
        {
            Huge result = new Huge();
            int  contor = 0;

            byte[] suma  = new byte[Math.Max(left.digits, right.Digits) + 1];
            int    carry = 0;
            int    i;

            for (i = 0; i < Math.Min(left.Digits, right.digits); i++)
            {
                suma[i] = (byte)((carry + left.data[i] + right.data[i]) % 10);
                contor++;
                carry = (carry + left.data[i] + right.data[i]) / 10;
            }
            int j;

            for (j = i; j < left.Digits; j++)
            {
                suma[j] = (byte)((carry + left.data[j]) % 10);
                contor++;
                carry = (carry + left.data[j]) / 10;
            }
            int k;

            for (k = i; k < right.Digits; k++)
            {
                suma[k] = (byte)((carry + right.data[k]) % 10);
                contor++;
                carry = (carry + right.data[k]) / 10;
            }
            if (carry > 0)
            {
                suma[Math.Max(j, k)] = (byte)carry;
                contor++;
            }
            result.data   = suma;
            result.digits = contor;
            return(result);
        }
示例#4
0
        public static Huge operator *(Huge left, Huge right)
        {
            Huge resultt = new Huge();
            int  contorr = 0;

            byte[] prod   = new byte[left.digits * right.Digits + 1];
            int    carryy = 0;

            int i;

            for (i = 0; i < Math.Min(left.Digits, right.digits); i++)
            {
                prod[i] = (byte)((carryy + left.data[i] * right.data[i]) % 10);
                contorr++;
                carryy = (carryy + left.data[i] * right.data[i]) / 10;
            }
            int j;

            for (j = i; j < left.Digits; j++)
            {
                prod[j] = (byte)((carryy * left.data[j]) % 10);
                contorr++;
                carryy = (carryy * left.data[i]) / 10;
            }
            for (j = i; j < right.Digits; j++)
            {
                prod[j] = (byte)((carryy * right.data[j]) % 10);
                contorr++;
                carryy = (carryy * right.data[i]) / 10;
            }
            if (carryy > 0)
            {
                prod[j] = (byte)carryy;
                contorr++;
            }
            resultt.data   = prod;
            resultt.digits = contorr;
            return(resultt);
        }
示例#5
0
        public static Huge operator+(Huge left, int right)
        {
            Huge rightH = new Huge(right);

            return(left + rightH);
        }