private static void MultiDivide(BigInteger leftSide, BigInteger rightSide, out BigInteger quotient, out BigInteger remainder) { if (rightSide.IsZero) { throw new DivideByZeroException(); } uint num = rightSide.m_digits[rightSide.m_digits.DataUsed - 1]; int num2 = 0; uint num3 = DigitsArray.HiBitSet; while (num3 != 0u && (num & num3) == 0u) { num2++; num3 >>= 1; } int num4 = leftSide.m_digits.DataUsed + 1; uint[] array = new uint[num4]; leftSide.m_digits.CopyTo(array, 0, leftSide.m_digits.DataUsed); DigitsArray.ShiftLeft(array, num2); rightSide <<= num2; ulong num5 = (ulong)rightSide.m_digits[rightSide.m_digits.DataUsed - 1]; ulong num6 = (ulong)((rightSide.m_digits.DataUsed >= 2) ? rightSide.m_digits[rightSide.m_digits.DataUsed - 2] : 0u); int num7 = rightSide.m_digits.DataUsed + 1; DigitsArray digitsArray = new DigitsArray(num7, num7); uint[] array2 = new uint[leftSide.m_digits.Count + 1]; int num8 = 0; ulong num9 = 1uL << DigitsArray.DataSizeBits; int i = num4 - rightSide.m_digits.DataUsed; int j = num4 - 1; while (i > 0) { ulong num10 = ((ulong)array[j] << DigitsArray.DataSizeBits) + (ulong)array[j - 1]; ulong num11 = num10 / num5; ulong num12 = num10 % num5; while (j >= 2) { if (num11 == num9 || num11 * num6 > (num12 << DigitsArray.DataSizeBits) + (ulong)array[j - 2]) { num11 -= 1uL; num12 += num5; if (num12 < num9) { continue; } } break; } for (int k = 0; k < num7; k++) { digitsArray[num7 - k - 1] = array[j - k]; } BigInteger bigInteger = new BigInteger(digitsArray); BigInteger bigInteger2 = rightSide * (long)num11; while (bigInteger2 > bigInteger) { num11 -= 1uL; bigInteger2 -= rightSide; } bigInteger2 = bigInteger - bigInteger2; for (int l = 0; l < num7; l++) { array[j - l] = bigInteger2.m_digits[rightSide.m_digits.DataUsed - l]; } array2[num8++] = (uint)num11; i--; j--; } Array.Reverse(array2, 0, num8); quotient = new BigInteger(new DigitsArray(array2)); int num13 = DigitsArray.ShiftRight(array, num2); DigitsArray digitsArray2 = new DigitsArray(num13, num13); digitsArray2.CopyFrom(array, 0, 0, digitsArray2.DataUsed); remainder = new BigInteger(digitsArray2); }
private static void MultiDivide(BigInteger leftSide, BigInteger rightSide, out BigInteger quotient, out BigInteger remainder) { BigInteger k; object item; if (rightSide.IsZero) { throw new DivideByZeroException(); } uint num = rightSide.m_digits[rightSide.m_digits.DataUsed - 1]; int num1 = 0; for (uint i = DigitsArray.HiBitSet; i != 0 && (num & i) == 0; i >>= 1) { num1++; } int dataUsed = leftSide.m_digits.DataUsed + 1; uint[] numArray = new uint[dataUsed]; leftSide.m_digits.CopyTo(numArray, 0, leftSide.m_digits.DataUsed); DigitsArray.ShiftLeft(numArray, num1); rightSide <<= num1; ulong item1 = (ulong)rightSide.m_digits[rightSide.m_digits.DataUsed - 1]; if (rightSide.m_digits.DataUsed >= 2) { item = rightSide.m_digits[rightSide.m_digits.DataUsed - 2]; } else { item = null; } ulong num2 = (ulong)item; int dataUsed1 = rightSide.m_digits.DataUsed + 1; DigitsArray digitsArray = new DigitsArray(dataUsed1, dataUsed1); uint[] numArray1 = new uint[leftSide.m_digits.Count + 1]; int num3 = 0; ulong dataSizeBits = (ulong)((long)1 << (DigitsArray.DataSizeBits & 63)); int dataUsed2 = dataUsed - rightSide.m_digits.DataUsed; int num4 = dataUsed - 1; while (dataUsed2 > 0) { ulong dataSizeBits1 = ((ulong)numArray[num4] << (DigitsArray.DataSizeBits & 63)) + (ulong)numArray[num4 - 1]; ulong num5 = dataSizeBits1 / item1; ulong num6 = dataSizeBits1 % item1; while (true) { if (num4 < 2) { goto Label0; } if (num5 != dataSizeBits && num5 * num2 <= (num6 << (DigitsArray.DataSizeBits & 63)) + (ulong)numArray[num4 - 2]) { break; } num5 -= (long)1; num6 += item1; if (num6 >= dataSizeBits) { break; } } for (int j = 0; j < dataUsed1; j++) { digitsArray[dataUsed1 - j - 1] = numArray[num4 - j]; } BigInteger bigInteger = new BigInteger(digitsArray); for (k = rightSide * num5; k > bigInteger; k -= rightSide) { num5 -= (long)1; } k = bigInteger - k; for (int l = 0; l < dataUsed1; l++) { numArray[num4 - l] = k.m_digits[rightSide.m_digits.DataUsed - l]; } int num7 = num3; num3 = num7 + 1; numArray1[num7] = (uint)num5; dataUsed2--; num4--; } Array.Reverse(numArray1, 0, num3); quotient = new BigInteger(new DigitsArray(numArray1)); int num8 = DigitsArray.ShiftRight(numArray, num1); DigitsArray digitsArray1 = new DigitsArray(num8, num8); digitsArray1.CopyFrom(numArray, 0, 0, digitsArray1.DataUsed); remainder = new BigInteger(digitsArray1); }
internal int ShiftLeft(int shiftCount) { return(DigitsArray.ShiftLeft(this.m_data, shiftCount)); }