public static BigInteger operator *(BigIntegerShell bi1, BigInteger bi2)
{
var result = new BigInteger(0);
// multiply the absolute values
try
{
for (int i = 0; i < bi1.Length; i++)
{
if (bi1[i] == 0) continue;
ulong mcarry = 0;
for (int j = 0, k = i; j < bi2.Length; j++, k++)
{
// k = i + j
ulong val = ((ulong)bi1[i] * (ulong)bi2.Data[j]) +
(ulong)result.Data[k] + mcarry;
result.Data[k] = (uint)(val & 0xFFFFFFFF);
mcarry = (val >> 32);
}
if (mcarry != 0)
result.Data[i + bi2.Length] = (uint)mcarry;
}
}
catch (Exception)
{
throw (new ArithmeticException("Multiplication overflow."));
}
result.Length = bi1.Length + bi2.Length;
while (result.Length > 1 && result.Data[result.Length - 1] == 0)
result.Length--;
return result;
}
}