public BigInteger Divide(
BigInteger val)
{
if (val.sign == 0)
throw new ArithmeticException("Division by zero error");
if (sign == 0)
return Zero;
if (val.QuickPow2Check()) // val is power of two
{
BigInteger result = this.Abs().ShiftRight(val.Abs().BitLength - 1);
return val.sign == this.sign ? result : result.Negate();
}
int[] mag = (int[]) this.magnitude.Clone();
return new BigInteger(this.sign * val.sign, Divide(mag, val.magnitude), true);
}