Пример #1
0
        public static BigInt operator *(BigInt V1, BigInt V2)  // v1 * v2
        {
            V1.DeleteNuls(); V2.DeleteNuls();
            var result = new BigInt();

            result.EqualizeTheDigits(V1.number.Count + V2.number.Count);
            V1.number.Reverse(); V2.number.Reverse();
            for (var i = 0; i < V1.number.Count; ++i)
            {
                for (int j = 0, carry = 0; j < V2.number.Count || carry > 0; ++j)
                {
                    var cur = result.number[i + j] + V1.number[i] * (j < V2.number.Count ? V2.number[j] : 0) + carry;
                    result.number[i + j] = cur % 10;
                    carry = cur / 10;
                }
            }
            while (result.number.Count > 1 && result.number.Last() == 0)
            {
                result.number.RemoveAt(result.number.Count - 1);
            }
            result.sign = V1.sign == V2.sign ? '+' : '-';
            V1.number.Reverse(); V2.number.Reverse();
            result.number.Reverse();
            result.DeleteNuls();
            return(result);
        }