public static BigInteger operator -(BigInteger leftSide, BigInteger rightSide)
        {
            object      obj;
            int         num         = Math.Max(leftSide.m_digits.DataUsed, rightSide.m_digits.DataUsed) + 1;
            DigitsArray digitsArray = new DigitsArray(num);
            long        num1        = (long)0;

            for (int i = 0; i < digitsArray.Count; i++)
            {
                long item = (long)((ulong)leftSide.m_digits[i] - (ulong)rightSide.m_digits[i] - num1);
                digitsArray[i] = (uint)(item & (ulong)DigitsArray.AllBits);
                DigitsArray dataUsed = digitsArray;
                dataUsed.DataUsed = dataUsed.DataUsed + 1;
                if (item >= (long)0)
                {
                    obj = null;
                }
                else
                {
                    obj = 1;
                }
                num1 = (long)obj;
            }
            return(new BigInteger(digitsArray));
        }
        public static BigInteger operator -(BigInteger leftSide)
        {
            if (object.ReferenceEquals(leftSide, null))
            {
                throw new ArgumentNullException("leftSide");
            }
            if (leftSide.IsZero)
            {
                return(new BigInteger(0L));
            }
            DigitsArray digitsArray = new DigitsArray(leftSide.m_digits.DataUsed + 1, leftSide.m_digits.DataUsed + 1);

            for (int i = 0; i < digitsArray.Count; i++)
            {
                digitsArray[i] = ~leftSide.m_digits[i];
            }
            bool flag = true;
            int  num  = 0;

            while (flag && num < digitsArray.Count)
            {
                long num2 = (long)((ulong)digitsArray[num] + 1uL);
                digitsArray[num] = (uint)(num2 & (long)((ulong)DigitsArray.AllBits));
                flag             = (num2 >> DigitsArray.DataSizeBits > 0L);
                num++;
            }
            return(new BigInteger(digitsArray));
        }
        public static BigInteger operator -(BigInteger leftSide)
        {
            if (object.ReferenceEquals(leftSide, null))
            {
                throw new ArgumentNullException("leftSide");
            }
            if (leftSide.IsZero)
            {
                return(new BigInteger((long)0));
            }
            DigitsArray digitsArray = new DigitsArray(leftSide.m_digits.DataUsed + 1, leftSide.m_digits.DataUsed + 1);

            for (int i = 0; i < digitsArray.Count; i++)
            {
                digitsArray[i] = ~leftSide.m_digits[i];
            }
            bool dataSizeBits = true;

            for (int j = 0; dataSizeBits && j < digitsArray.Count; j++)
            {
                long item = (long)((ulong)digitsArray[j] + (long)1);
                digitsArray[j] = (uint)(item & (ulong)DigitsArray.AllBits);
                dataSizeBits   = item >> (DigitsArray.DataSizeBits & 63) > (long)0;
            }
            return(new BigInteger(digitsArray));
        }
        public static BigInteger operator >>(BigInteger leftSide, int shiftCount)
        {
            if (leftSide == null)
            {
                throw new ArgumentNullException("leftSide");
            }
            DigitsArray digitsArray = new DigitsArray(leftSide.m_digits);

            digitsArray.DataUsed = digitsArray.ShiftRight(shiftCount);
            if (leftSide.IsNegative)
            {
                for (int i = digitsArray.Count - 1; i >= digitsArray.DataUsed; i--)
                {
                    digitsArray[i] = DigitsArray.AllBits;
                }
                uint num = DigitsArray.HiBitSet;
                for (int j = 0; j < DigitsArray.DataSizeBits; j++)
                {
                    if ((digitsArray[digitsArray.DataUsed - 1] & num) == DigitsArray.HiBitSet)
                    {
                        break;
                    }
                    DigitsArray digitsArray2;
                    DigitsArray expr_92 = digitsArray2 = digitsArray;
                    int         index;
                    int         expr_9D = index = digitsArray.DataUsed - 1;
                    uint        num2    = digitsArray2[index];
                    expr_92[expr_9D] = (num2 | num);
                    num >>= 1;
                }
                digitsArray.DataUsed = digitsArray.Count;
            }
            return(new BigInteger(digitsArray));
        }
        public static BigInteger operator ~(BigInteger leftSide)
        {
            DigitsArray digitsArray = new DigitsArray(leftSide.m_digits.Count);

            for (int i = 0; i < digitsArray.Count; i++)
            {
                digitsArray[i] = ~leftSide.m_digits[i];
            }
            return(new BigInteger(digitsArray));
        }
        public static BigInteger operator <<(BigInteger leftSide, int shiftCount)
        {
            if (leftSide == null)
            {
                throw new ArgumentNullException("leftSide");
            }
            DigitsArray digitsArray = new DigitsArray(leftSide.m_digits);

            digitsArray.DataUsed = digitsArray.ShiftLeftWithoutOverflow(shiftCount);
            return(new BigInteger(digitsArray));
        }
        public static BigInteger operator ^(BigInteger leftSide, BigInteger rightSide)
        {
            int         num         = Math.Max(leftSide.m_digits.DataUsed, rightSide.m_digits.DataUsed);
            DigitsArray digitsArray = new DigitsArray(num, num);

            for (int i = 0; i < num; i++)
            {
                digitsArray[i] = leftSide.m_digits[i] ^ rightSide.m_digits[i];
            }
            return(new BigInteger(digitsArray));
        }
 public BigInteger(ulong number)
 {
     this.m_digits = new DigitsArray(8 / DigitsArray.DataSizeOf + 1, 0);
     while (number != 0uL && this.m_digits.DataUsed < this.m_digits.Count)
     {
         this.m_digits[this.m_digits.DataUsed] = (uint)(number & (ulong)DigitsArray.AllBits);
         number >>= DigitsArray.DataSizeBits;
         this.m_digits.DataUsed++;
     }
     this.m_digits.ResetDataUsed();
 }
 public BigInteger(ulong number)
 {
     this.m_digits = new DigitsArray(8 / DigitsArray.DataSizeOf + 1, 0);
     while (number != (long)0 && this.m_digits.DataUsed < this.m_digits.Count)
     {
         this.m_digits[this.m_digits.DataUsed] = (uint)(number & (ulong)DigitsArray.AllBits);
         number = number >> (DigitsArray.DataSizeBits & 63);
         DigitsArray mDigits = this.m_digits;
         mDigits.DataUsed = mDigits.DataUsed + 1;
     }
     this.m_digits.ResetDataUsed();
 }
        public static BigInteger operator +(BigInteger leftSide, BigInteger rightSide)
        {
            int         num         = Math.Max(leftSide.m_digits.DataUsed, rightSide.m_digits.DataUsed);
            DigitsArray digitsArray = new DigitsArray(num + 1);
            long        num2        = 0L;

            for (int i = 0; i < digitsArray.Count; i++)
            {
                long num3 = (long)((ulong)leftSide.m_digits[i] + (ulong)rightSide.m_digits[i] + (ulong)num2);
                num2           = num3 >> DigitsArray.DataSizeBits;
                digitsArray[i] = (uint)(num3 & (long)((ulong)DigitsArray.AllBits));
            }
            return(new BigInteger(digitsArray));
        }
        public static BigInteger operator +(BigInteger leftSide, BigInteger rightSide)
        {
            int         num          = Math.Max(leftSide.m_digits.DataUsed, rightSide.m_digits.DataUsed);
            DigitsArray digitsArray  = new DigitsArray(num + 1);
            long        dataSizeBits = (long)0;

            for (int i = 0; i < digitsArray.Count; i++)
            {
                long item = (long)((ulong)leftSide.m_digits[i] + (ulong)rightSide.m_digits[i] + dataSizeBits);
                dataSizeBits   = item >> (DigitsArray.DataSizeBits & 63);
                digitsArray[i] = (uint)(item & (ulong)DigitsArray.AllBits);
            }
            return(new BigInteger(digitsArray));
        }
        private static void SingleDivide(BigInteger leftSide, BigInteger rightSide, out BigInteger quotient, out BigInteger remainder)
        {
            if (rightSide.IsZero)
            {
                throw new DivideByZeroException();
            }
            DigitsArray digitsArray = new DigitsArray(leftSide.m_digits);

            digitsArray.ResetDataUsed();
            int   dataUsed = digitsArray.DataUsed - 1;
            ulong item     = (ulong)rightSide.m_digits[0];
            ulong num      = (ulong)digitsArray[dataUsed];

            uint[] numArray = new uint[leftSide.m_digits.Count];
            leftSide.m_digits.CopyTo(numArray, 0, (int)numArray.Length);
            int num1 = 0;

            if (num >= item)
            {
                int num2 = num1;
                num1                  = num2 + 1;
                numArray[num2]        = (uint)(num / item);
                digitsArray[dataUsed] = (uint)(num % item);
            }
            dataUsed--;
            while (dataUsed >= 0)
            {
                num = ((ulong)digitsArray[dataUsed + 1] << (DigitsArray.DataSizeBits & 63)) + (ulong)digitsArray[dataUsed];
                int num3 = num1;
                num1                      = num3 + 1;
                numArray[num3]            = (uint)(num / item);
                digitsArray[dataUsed + 1] = 0;
                int num4 = dataUsed;
                dataUsed          = num4 - 1;
                digitsArray[num4] = (uint)(num % item);
            }
            remainder = new BigInteger(digitsArray);
            DigitsArray digitsArray1 = new DigitsArray(num1 + 1, num1);
            int         num5         = 0;
            int         dataUsed1    = digitsArray1.DataUsed - 1;

            while (dataUsed1 >= 0)
            {
                digitsArray1[num5] = numArray[dataUsed1];
                dataUsed1--;
                num5++;
            }
            quotient = new BigInteger(digitsArray1);
        }
        public static BigInteger operator -(BigInteger leftSide, BigInteger rightSide)
        {
            int         size        = Math.Max(leftSide.m_digits.DataUsed, rightSide.m_digits.DataUsed) + 1;
            DigitsArray digitsArray = new DigitsArray(size);
            long        num         = 0L;

            for (int i = 0; i < digitsArray.Count; i++)
            {
                long num2 = (long)((ulong)leftSide.m_digits[i] - (ulong)rightSide.m_digits[i] - (ulong)num);
                digitsArray[i] = (uint)(num2 & (long)((ulong)DigitsArray.AllBits));
                digitsArray.DataUsed++;
                num = ((num2 >= 0L) ? 0L : 1L);
            }
            return(new BigInteger(digitsArray));
        }
        private void ConstructFrom(byte[] array, int offset, int length)
        {
            if (array == null)
            {
                throw new ArgumentNullException("array");
            }
            if (offset > (int)array.Length || length > (int)array.Length)
            {
                throw new ArgumentOutOfRangeException("offset");
            }
            if (length > (int)array.Length || offset + length > (int)array.Length)
            {
                throw new ArgumentOutOfRangeException("length");
            }
            int num  = length / 4;
            int num1 = length & 3;

            if (num1 != 0)
            {
                num++;
            }
            this.m_digits = new DigitsArray(num + 1, 0);
            int num2 = offset + length - 1;
            int num3 = 0;

            while (num2 - offset >= 3)
            {
                this.m_digits[num3] = (uint)((array[num2 - 3] << 24) + (array[num2 - 2] << 16) + (array[num2 - 1] << 8) + array[num2]);
                DigitsArray mDigits = this.m_digits;
                mDigits.DataUsed = mDigits.DataUsed + 1;
                num2            -= 4;
                num3++;
            }
            uint num4 = 0;

            for (int i = num1; i > 0; i--)
            {
                uint num5 = array[offset + num1 - i];
                num5  = num5 << ((i - 1) * 8 & 31);
                num4 |= num5;
            }
            this.m_digits[this.m_digits.DataUsed] = num4;
            this.m_digits.ResetDataUsed();
        }
        private static void SingleDivide(BigInteger leftSide, BigInteger rightSide, out BigInteger quotient, out BigInteger remainder)
        {
            if (rightSide.IsZero)
            {
                throw new DivideByZeroException();
            }
            DigitsArray digitsArray = new DigitsArray(leftSide.m_digits);

            digitsArray.ResetDataUsed();
            int   i    = digitsArray.DataUsed - 1;
            ulong num  = (ulong)rightSide.m_digits[0];
            ulong num2 = (ulong)digitsArray[i];

            uint[] array = new uint[leftSide.m_digits.Count];
            leftSide.m_digits.CopyTo(array, 0, array.Length);
            int num3 = 0;

            if (num2 >= num)
            {
                array[num3++]  = (uint)(num2 / num);
                digitsArray[i] = (uint)(num2 % num);
            }
            i--;
            while (i >= 0)
            {
                num2               = ((ulong)digitsArray[i + 1] << DigitsArray.DataSizeBits) + (ulong)digitsArray[i];
                array[num3++]      = (uint)(num2 / num);
                digitsArray[i + 1] = 0u;
                digitsArray[i--]   = (uint)(num2 % num);
            }
            remainder = new BigInteger(digitsArray);
            DigitsArray digitsArray2 = new DigitsArray(num3 + 1, num3);
            int         num4         = 0;
            int         j            = digitsArray2.DataUsed - 1;

            while (j >= 0)
            {
                digitsArray2[num4] = array[j];
                j--;
                num4++;
            }
            quotient = new BigInteger(digitsArray2);
        }
        private void ConstructFrom(byte[] array, int offset, int length)
        {
            if (array == null)
            {
                throw new ArgumentNullException("array");
            }
            if (offset > array.Length || length > array.Length)
            {
                throw new ArgumentOutOfRangeException("offset");
            }
            if (length > array.Length || offset + length > array.Length)
            {
                throw new ArgumentOutOfRangeException("length");
            }
            int num  = length / 4;
            int num2 = length & 3;

            if (num2 != 0)
            {
                num++;
            }
            this.m_digits = new DigitsArray(num + 1, 0);
            int num3 = offset + length - 1;
            int num4 = 0;

            while (num3 - offset >= 3)
            {
                this.m_digits[num4] = (uint)(((int)array[num3 - 3] << 24) + ((int)array[num3 - 2] << 16) + ((int)array[num3 - 1] << 8) + (int)array[num3]);
                this.m_digits.DataUsed++;
                num3 -= 4;
                num4++;
            }
            uint num5 = 0u;

            for (int i = num2; i > 0; i--)
            {
                uint num6 = (uint)array[offset + num2 - i];
                num6 <<= (i - 1) * 8;
                num5  |= num6;
            }
            this.m_digits[this.m_digits.DataUsed] = num5;
            this.m_digits.ResetDataUsed();
        }
        public static BigInteger operator *(BigInteger leftSide, BigInteger rightSide)
        {
            if (object.ReferenceEquals(leftSide, null))
            {
                throw new ArgumentNullException("leftSide");
            }
            if (object.ReferenceEquals(rightSide, null))
            {
                throw new ArgumentNullException("rightSide");
            }
            bool isNegative = leftSide.IsNegative;
            bool flag       = rightSide.IsNegative;

            leftSide  = BigInteger.Abs(leftSide);
            rightSide = BigInteger.Abs(rightSide);
            DigitsArray digitsArray = new DigitsArray(leftSide.m_digits.DataUsed + rightSide.m_digits.DataUsed)
            {
                DataUsed = digitsArray.Count
            };

            for (int i = 0; i < leftSide.m_digits.DataUsed; i++)
            {
                ulong dataSizeBits = (ulong)0;
                int   num          = 0;
                int   num1         = i;
                while (num < rightSide.m_digits.DataUsed)
                {
                    ulong item = (ulong)leftSide.m_digits[i] * (ulong)rightSide.m_digits[num] + (ulong)digitsArray[num1] + dataSizeBits;
                    digitsArray[num1] = (uint)(item & (ulong)DigitsArray.AllBits);
                    dataSizeBits      = item >> (DigitsArray.DataSizeBits & 63);
                    num++;
                    num1++;
                }
                if (dataSizeBits != (long)0)
                {
                    digitsArray[i + rightSide.m_digits.DataUsed] = (uint)dataSizeBits;
                }
            }
            BigInteger bigInteger = new BigInteger(digitsArray);

            return(isNegative == flag ? bigInteger : -bigInteger);
        }
        public static BigInteger operator *(BigInteger leftSide, BigInteger rightSide)
        {
            if (object.ReferenceEquals(leftSide, null))
            {
                throw new ArgumentNullException("leftSide");
            }
            if (object.ReferenceEquals(rightSide, null))
            {
                throw new ArgumentNullException("rightSide");
            }
            bool isNegative  = leftSide.IsNegative;
            bool isNegative2 = rightSide.IsNegative;

            leftSide  = BigInteger.Abs(leftSide);
            rightSide = BigInteger.Abs(rightSide);
            DigitsArray digitsArray = new DigitsArray(leftSide.m_digits.DataUsed + rightSide.m_digits.DataUsed);

            digitsArray.DataUsed = digitsArray.Count;
            for (int i = 0; i < leftSide.m_digits.DataUsed; i++)
            {
                ulong num  = 0uL;
                int   j    = 0;
                int   num2 = i;
                while (j < rightSide.m_digits.DataUsed)
                {
                    ulong num3 = (ulong)leftSide.m_digits[i] * (ulong)rightSide.m_digits[j] + (ulong)digitsArray[num2] + num;
                    digitsArray[num2] = (uint)(num3 & (ulong)DigitsArray.AllBits);
                    num = num3 >> DigitsArray.DataSizeBits;
                    j++;
                    num2++;
                }
                if (num != 0uL)
                {
                    digitsArray[i + rightSide.m_digits.DataUsed] = (uint)num;
                }
            }
            BigInteger bigInteger = new BigInteger(digitsArray);

            return((isNegative == isNegative2) ? bigInteger : (-bigInteger));
        }
        private void Construct(string digits, int radix)
        {
            if (digits == null)
            {
                throw new ArgumentNullException("digits");
            }
            BigInteger leftSide   = new BigInteger(1L);
            BigInteger bigInteger = new BigInteger();

            digits = digits.ToUpper(CultureInfo.get_CurrentCulture()).Trim();
            int num = (digits.get_Chars(0) != '-') ? 0 : 1;

            for (int i = digits.get_Length() - 1; i >= num; i--)
            {
                int num2 = (int)digits.get_Chars(i);
                if (num2 >= 48 && num2 <= 57)
                {
                    num2 -= 48;
                }
                else
                {
                    if (num2 < 65 || num2 > 90)
                    {
                        throw new ArgumentOutOfRangeException("digits");
                    }
                    num2 = num2 - 65 + 10;
                }
                if (num2 >= radix)
                {
                    throw new ArgumentOutOfRangeException("digits");
                }
                bigInteger += leftSide * num2;
                leftSide   *= radix;
            }
            if (digits.get_Chars(0) == '-')
            {
                bigInteger = -bigInteger;
            }
            this.m_digits = bigInteger.m_digits;
        }
        private void Construct(string digits, int radix)
        {
            if (digits == null)
            {
                throw new ArgumentNullException("digits");
            }
            BigInteger bigInteger  = new BigInteger((long)1);
            BigInteger bigInteger1 = new BigInteger();

            digits = digits.ToUpper(CultureInfo.CurrentCulture).Trim();
            int num = (digits[0] != '-' ? 0 : 1);

            for (int i = digits.Length - 1; i >= num; i--)
            {
                int num1 = digits[i];
                if (num1 < 48 || num1 > 57)
                {
                    if (num1 < 65 || num1 > 90)
                    {
                        throw new ArgumentOutOfRangeException("digits");
                    }
                    num1 = num1 - 65 + 10;
                }
                else
                {
                    num1 -= 48;
                }
                if (num1 >= radix)
                {
                    throw new ArgumentOutOfRangeException("digits");
                }
                bigInteger1 = bigInteger1 + (bigInteger * num1);
                bigInteger *= radix;
            }
            if (digits[0] == '-')
            {
                bigInteger1 = -bigInteger1;
            }
            this.m_digits = bigInteger1.m_digits;
        }
        public static BigInteger operator >>(BigInteger leftSide, int shiftCount)
        {
            if (leftSide == null)
            {
                throw new ArgumentNullException("leftSide");
            }
            DigitsArray digitsArray = new DigitsArray(leftSide.m_digits)
            {
                DataUsed = digitsArray.ShiftRight(shiftCount)
            };

            if (leftSide.IsNegative)
            {
                for (int i = digitsArray.Count - 1; i >= digitsArray.DataUsed; i--)
                {
                    digitsArray[i] = DigitsArray.AllBits;
                }
                uint hiBitSet = DigitsArray.HiBitSet;
                int  num      = 0;
                while (num < DigitsArray.DataSizeBits)
                {
                    if ((digitsArray[digitsArray.DataUsed - 1] & hiBitSet) != DigitsArray.HiBitSet)
                    {
                        DigitsArray item         = digitsArray;
                        DigitsArray digitsArray1 = item;
                        int         dataUsed     = digitsArray.DataUsed - 1;
                        item[dataUsed] = digitsArray1[dataUsed] | hiBitSet;
                        hiBitSet     >>= 1;
                        num++;
                    }
                    else
                    {
                        break;
                    }
                }
                digitsArray.DataUsed = digitsArray.Count;
            }
            return(new BigInteger(digitsArray));
        }
示例#22
0
 internal int ShiftLeft(int shiftCount)
 {
     return(DigitsArray.ShiftLeft(this.m_data, shiftCount));
 }
 private BigInteger(DigitsArray digits)
 {
     digits.ResetDataUsed();
     this.m_digits = digits;
 }
        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);
        }
示例#25
0
 internal DigitsArray(DigitsArray copyFrom)
 {
     this.Allocate(copyFrom.Count, copyFrom.DataUsed);
     Array.Copy(copyFrom.m_data, 0, this.m_data, 0, copyFrom.Count);
 }
 public BigInteger()
 {
     this.m_digits = new DigitsArray(1, 1);
 }
        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);
        }