Advertisement
Guest User

Untitled

a guest
Aug 25th, 2012
1,180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 78.85 KB | None | 0 0
  1. [Serializable]
  2. public struct BigInteger : IFormattable, IComparable, IComparable<BigInteger>, IEquatable<BigInteger>
  3. {
  4.     internal uint[] _bits;
  5.  
  6.     internal int _sign;
  7.  
  8.     private const int DecimalScaleFactorMask = 16711680;
  9.  
  10.     private const int DecimalSignMask = -2147483648;
  11.  
  12.     private const int kcbitUint = 32;
  13.  
  14.     private const int kcbitUlong = 64;
  15.  
  16.     private const int knMaskHighBit = -2147483648;
  17.  
  18.     private const uint kuMaskHighBit = 2147483648;
  19.  
  20.     private readonly static BigInteger s_bnMinInt;
  21.  
  22.     private readonly static BigInteger s_bnMinusOneInt;
  23.  
  24.     private readonly static BigInteger s_bnOneInt;
  25.  
  26.     private readonly static BigInteger s_bnZeroInt;
  27.  
  28.     internal uint[] _Bits
  29.     {
  30.         get
  31.         {
  32.             return this._bits;
  33.         }
  34.     }
  35.  
  36.     internal int _Sign
  37.     {
  38.         get
  39.         {
  40.             return this._sign;
  41.         }
  42.     }
  43.  
  44.     public bool IsEven
  45.     {
  46.         get
  47.         {
  48.             if (this._bits == null)
  49.             {
  50.                 return (this._sign & 1) == 0;
  51.             }
  52.             else
  53.             {
  54.                 return (this._bits[0] & 1) == 0;
  55.             }
  56.         }
  57.     }
  58.  
  59.     public bool IsOne
  60.     {
  61.         get
  62.         {
  63.             if (this._sign != 1)
  64.             {
  65.                 return false;
  66.             }
  67.             else
  68.             {
  69.                 return this._bits == null;
  70.             }
  71.         }
  72.     }
  73.  
  74.     public bool IsPowerOfTwo
  75.     {
  76.         get
  77.         {
  78.             if (this._bits != null)
  79.             {
  80.                 if (this._sign == 1)
  81.                 {
  82.                     int num = BigInteger.Length(this._bits) - 1;
  83.                     if ((this._bits[num] & this._bits[num] - 1) == 0)
  84.                     {
  85.                         do
  86.                         {
  87.                             int num1 = num - 1;
  88.                             num = num1;
  89.                             if (num1 >= 0)
  90.                             {
  91.                                 continue;
  92.                             }
  93.                             return true;
  94.                         }
  95.                         while (this._bits[num] == 0);
  96.                         return false;
  97.                     }
  98.                     else
  99.                     {
  100.                         return false;
  101.                     }
  102.                 }
  103.                 else
  104.                 {
  105.                     return false;
  106.                 }
  107.             }
  108.             else
  109.             {
  110.                 if ((this._sign & this._sign - 1) != 0)
  111.                 {
  112.                     return false;
  113.                 }
  114.                 else
  115.                 {
  116.                     return this._sign != 0;
  117.                 }
  118.             }
  119.         }
  120.     }
  121.  
  122.     public bool IsZero
  123.     {
  124.         get
  125.         {
  126.             return this._sign == 0;
  127.         }
  128.     }
  129.  
  130.     public static BigInteger MinusOne
  131.     {
  132.         [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
  133.         get
  134.         {
  135.             return BigInteger.s_bnMinusOneInt;
  136.         }
  137.     }
  138.  
  139.     public static BigInteger One
  140.     {
  141.         [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
  142.         get
  143.         {
  144.             return BigInteger.s_bnOneInt;
  145.         }
  146.     }
  147.  
  148.     public int Sign
  149.     {
  150.         get
  151.         {
  152.             return (this._sign >> 31) - (-this._sign >> 31);
  153.         }
  154.     }
  155.  
  156.     public static BigInteger Zero
  157.     {
  158.         [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
  159.         get
  160.         {
  161.             return BigInteger.s_bnZeroInt;
  162.         }
  163.     }
  164.  
  165.     static BigInteger()
  166.     {
  167.         uint[] numArray = new uint[1];
  168.         numArray[0] = -2147483648;
  169.         BigInteger.s_bnMinInt = new BigInteger(-1, numArray);
  170.         BigInteger.s_bnOneInt = new BigInteger(1);
  171.         BigInteger.s_bnZeroInt = new BigInteger(0);
  172.         BigInteger.s_bnMinusOneInt = new BigInteger(-1);
  173.     }
  174.  
  175.     public BigInteger(int value)
  176.     {
  177.         if (value != -2147483648)
  178.         {
  179.             this._sign = value;
  180.             this._bits = null;
  181.             return;
  182.         }
  183.         else
  184.         {
  185.             *(this) = BigInteger.s_bnMinInt;
  186.             return;
  187.         }
  188.     }
  189.  
  190.     [CLSCompliant(false)]
  191.     public BigInteger(uint value)
  192.     {
  193.         if (value > 2147483647)
  194.         {
  195.             this._sign = 1;
  196.             this._bits = new uint[1];
  197.             this._bits[0] = value;
  198.             return;
  199.         }
  200.         else
  201.         {
  202.             this._sign = value;
  203.             this._bits = null;
  204.             return;
  205.         }
  206.     }
  207.  
  208.     public BigInteger(long value)
  209.     {
  210.         ulong num;
  211.         if ((long)-2147483648 > value || value > (long)2147483647)
  212.         {
  213.             if (value >= (long)0)
  214.             {
  215.                 num = value;
  216.                 this._sign = 1;
  217.             }
  218.             else
  219.             {
  220.                 num = -value;
  221.                 this._sign = -1;
  222.             }
  223.             this._bits = new uint[2];
  224.             this._bits[0] = (uint)num;
  225.             this._bits[1] = (uint)(num >> 32);
  226.             return;
  227.         }
  228.         else
  229.         {
  230.             if (value != (long)-2147483648)
  231.             {
  232.                 this._sign = (int)value;
  233.                 this._bits = null;
  234.                 return;
  235.             }
  236.             else
  237.             {
  238.                 *(this) = BigInteger.s_bnMinInt;
  239.                 return;
  240.             }
  241.         }
  242.     }
  243.  
  244.     [CLSCompliant(false)]
  245.     public BigInteger(ulong value)
  246.     {
  247.         if (value > (long)2147483647)
  248.         {
  249.             this._sign = 1;
  250.             this._bits = new uint[2];
  251.             this._bits[0] = (uint)value;
  252.             this._bits[1] = (uint)(value >> 32);
  253.             return;
  254.         }
  255.         else
  256.         {
  257.             this._sign = (int)value;
  258.             this._bits = null;
  259.             return;
  260.         }
  261.     }
  262.  
  263.     public BigInteger(float value)
  264.     {
  265.         if (!float.IsInfinity(value))
  266.         {
  267.             if (!float.IsNaN(value))
  268.             {
  269.                 this._sign = 0;
  270.                 this._bits = null;
  271.                 this.SetBitsFromDouble((double)value);
  272.                 return;
  273.             }
  274.             else
  275.             {
  276.                 throw new OverflowException(SR.GetString("Overflow_NotANumber"));
  277.             }
  278.         }
  279.         else
  280.         {
  281.             throw new OverflowException(SR.GetString("Overflow_BigIntInfinity"));
  282.         }
  283.     }
  284.  
  285.     public BigInteger(double value)
  286.     {
  287.         if (!double.IsInfinity(value))
  288.         {
  289.             if (!double.IsNaN(value))
  290.             {
  291.                 this._sign = 0;
  292.                 this._bits = null;
  293.                 this.SetBitsFromDouble(value);
  294.                 return;
  295.             }
  296.             else
  297.             {
  298.                 throw new OverflowException(SR.GetString("Overflow_NotANumber"));
  299.             }
  300.         }
  301.         else
  302.         {
  303.             throw new OverflowException(SR.GetString("Overflow_BigIntInfinity"));
  304.         }
  305.     }
  306.  
  307.     public BigInteger(decimal value)
  308.     {
  309.         byte num;
  310.         int num1;
  311.         int[] bits = decimal.GetBits(decimal.Truncate(value));
  312.         int num2 = 3;
  313.         while (num2 > 0 && bits[num2 - 1] == 0)
  314.         {
  315.             num2--;
  316.         }
  317.         if (num2 != 0)
  318.         {
  319.             if (num2 != 1 || bits[0] <= 0)
  320.             {
  321.                 this._bits = new uint[num2];
  322.                 this._bits[0] = bits[0];
  323.                 if (num2 > 1)
  324.                 {
  325.                     this._bits[1] = bits[1];
  326.                 }
  327.                 if (num2 > 2)
  328.                 {
  329.                     this._bits[2] = bits[2];
  330.                 }
  331.                 BigInteger bigInteger = this;
  332.                 if ((bits[3] & -2147483648) != 0)
  333.                 {
  334.                     num = -1;
  335.                 }
  336.                 else
  337.                 {
  338.                     num = 1;
  339.                 }
  340.                 bigInteger._sign = (int)num;
  341.                 return;
  342.             }
  343.             else
  344.             {
  345.                 this._sign = bits[0];
  346.                 BigInteger bigInteger1 = this;
  347.                 int num3 = bigInteger1._sign;
  348.                 if ((bits[3] & -2147483648) != 0)
  349.                 {
  350.                     num1 = -1;
  351.                 }
  352.                 else
  353.                 {
  354.                     num1 = 1;
  355.                 }
  356.                 bigInteger1._sign = num3 * num1;
  357.                 this._bits = null;
  358.                 return;
  359.             }
  360.         }
  361.         else
  362.         {
  363.             *(this) = BigInteger.s_bnZeroInt;
  364.             return;
  365.         }
  366.     }
  367.  
  368.     [CLSCompliant(false)]
  369.     public BigInteger(byte[] value)
  370.     {
  371.         bool flag;
  372.         int num;
  373.         int num1;
  374.         if (value != null)
  375.         {
  376.             int length = (int)value.Length;
  377.             if (length <= 0)
  378.             {
  379.                 flag = false;
  380.             }
  381.             else
  382.             {
  383.                 flag = (value[length - 1] & 128) == 128;
  384.             }
  385.             bool flag1 = flag;
  386.             while (length > 0 && value[length - 1] == 0)
  387.             {
  388.                 length--;
  389.             }
  390.             if (length != 0)
  391.             {
  392.                 if (length > 4)
  393.                 {
  394.                     int num2 = length % 4;
  395.                     int num3 = length / 4;
  396.                     if (num2 == 0)
  397.                     {
  398.                         num = 0;
  399.                     }
  400.                     else
  401.                     {
  402.                         num = 1;
  403.                     }
  404.                     int num4 = num3 + num;
  405.                     bool flag2 = true;
  406.                     uint[] numArray = new uint[num4];
  407.                     int j = 3;
  408.                     int num5 = 0;
  409.                     while (true)
  410.                     {
  411.                         int num6 = num5;
  412.                         int num7 = num4;
  413.                         if (num2 == 0)
  414.                         {
  415.                             num1 = 0;
  416.                         }
  417.                         else
  418.                         {
  419.                             num1 = 1;
  420.                         }
  421.                         if (num6 >= num7 - num1)
  422.                         {
  423.                             break;
  424.                         }
  425.                         for (int i = 0; i < 4; i++)
  426.                         {
  427.                             if (value[j] != 0)
  428.                             {
  429.                                 flag2 = false;
  430.                             }
  431.                             numArray[num5] = numArray[num5] << 8;
  432.                             numArray[num5] = numArray[num5] | value[j];
  433.                             j--;
  434.                         }
  435.                         j = j + 8;
  436.                         num5++;
  437.                     }
  438.                     if (num2 != 0)
  439.                     {
  440.                         if (flag1)
  441.                         {
  442.                             numArray[num4 - 1] = -1;
  443.                         }
  444.                         for (j = length - 1; j >= length - num2; j--)
  445.                         {
  446.                             if (value[j] != 0)
  447.                             {
  448.                                 flag2 = false;
  449.                             }
  450.                             numArray[num5] = numArray[num5] << 8;
  451.                             numArray[num5] = numArray[num5] | value[j];
  452.                         }
  453.                     }
  454.                     if (!flag2)
  455.                     {
  456.                         if (!flag1)
  457.                         {
  458.                             this._sign = 1;
  459.                             this._bits = numArray;
  460.                         }
  461.                         else
  462.                         {
  463.                             NumericsHelpers.DangerousMakeTwosComplement(numArray);
  464.                             int length1 = (int)numArray.Length;
  465.                             while (length1 > 0 && numArray[length1 - 1] == 0)
  466.                             {
  467.                                 length1--;
  468.                             }
  469.                             if (length1 != 1 || numArray[0] <= 0)
  470.                             {
  471.                                 if (length1 == (int)numArray.Length)
  472.                                 {
  473.                                     this._sign = -1;
  474.                                     this._bits = numArray;
  475.                                     return;
  476.                                 }
  477.                                 else
  478.                                 {
  479.                                     this._sign = -1;
  480.                                     this._bits = new uint[length1];
  481.                                     Array.Copy(numArray, this._bits, length1);
  482.                                     return;
  483.                                 }
  484.                             }
  485.                             else
  486.                             {
  487.                                 if (numArray[0] != 1)
  488.                                 {
  489.                                     if (numArray[0] != -2147483648)
  490.                                     {
  491.                                         this._sign = -1 * numArray[0];
  492.                                         this._bits = null;
  493.                                         return;
  494.                                     }
  495.                                     else
  496.                                     {
  497.                                         *(this) = BigInteger.s_bnMinInt;
  498.                                         return;
  499.                                     }
  500.                                 }
  501.                                 else
  502.                                 {
  503.                                     *(this) = BigInteger.s_bnMinusOneInt;
  504.                                     return;
  505.                                 }
  506.                             }
  507.                         }
  508.                     }
  509.                     else
  510.                     {
  511.                         *(this) = BigInteger.s_bnZeroInt;
  512.                         return;
  513.                     }
  514.                 }
  515.                 else
  516.                 {
  517.                     if (!flag1)
  518.                     {
  519.                         this._sign = 0;
  520.                     }
  521.                     else
  522.                     {
  523.                         this._sign = -1;
  524.                     }
  525.                     for (int k = length - 1; k >= 0; k--)
  526.                     {
  527.                         BigInteger bigInteger = this;
  528.                         bigInteger._sign = bigInteger._sign << 8;
  529.                         BigInteger bigInteger1 = this;
  530.                         bigInteger1._sign = bigInteger1._sign | value[k];
  531.                     }
  532.                     this._bits = null;
  533.                     if (this._sign < 0 && !flag1)
  534.                     {
  535.                         this._bits = new uint[1];
  536.                         this._bits[0] = this._sign;
  537.                         this._sign = 1;
  538.                     }
  539.                     if (this._sign == -2147483648)
  540.                     {
  541.                         *(this) = BigInteger.s_bnMinInt;
  542.                         return;
  543.                     }
  544.                 }
  545.                 return;
  546.             }
  547.             else
  548.             {
  549.                 this._sign = 0;
  550.                 this._bits = null;
  551.                 return;
  552.             }
  553.         }
  554.         else
  555.         {
  556.             throw new ArgumentNullException("value");
  557.         }
  558.     }
  559.  
  560.     internal BigInteger(int n, uint[] rgu)
  561.     {
  562.         this._sign = n;
  563.         this._bits = rgu;
  564.     }
  565.  
  566.     internal BigInteger(uint[] value, bool negative)
  567.     {
  568.         byte num;
  569.         uint num1;
  570.         if (value != null)
  571.         {
  572.             int length = (int)value.Length;
  573.             while (length > 0 && value[length - 1] == 0)
  574.             {
  575.                 length--;
  576.             }
  577.             if (length != 0)
  578.             {
  579.                 if (length != 1 || value[0] >= -2147483648)
  580.                 {
  581.                     BigInteger bigInteger = this;
  582.                     if (negative)
  583.                     {
  584.                         num = -1;
  585.                     }
  586.                     else
  587.                     {
  588.                         num = 1;
  589.                     }
  590.                     bigInteger._sign = (int)num;
  591.                     this._bits = new uint[length];
  592.                     Array.Copy(value, this._bits, length);
  593.                 }
  594.                 else
  595.                 {
  596.                     BigInteger bigInteger1 = this;
  597.                     if (negative)
  598.                     {
  599.                         num1 = -value[0];
  600.                     }
  601.                     else
  602.                     {
  603.                         num1 = value[0];
  604.                     }
  605.                     bigInteger1._sign = (int)num1;
  606.                     this._bits = null;
  607.                     if (this._sign == -2147483648)
  608.                     {
  609.                         *(this) = BigInteger.s_bnMinInt;
  610.                         return;
  611.                     }
  612.                 }
  613.                 return;
  614.             }
  615.             else
  616.             {
  617.                 *(this) = BigInteger.s_bnZeroInt;
  618.                 return;
  619.             }
  620.         }
  621.         else
  622.         {
  623.             throw new ArgumentNullException("value");
  624.         }
  625.     }
  626.  
  627.     private BigInteger(uint[] value)
  628.     {
  629.         bool flag;
  630.         if (value != null)
  631.         {
  632.             int length = (int)value.Length;
  633.             if (length <= 0)
  634.             {
  635.                 flag = false;
  636.             }
  637.             else
  638.             {
  639.                 flag = (value[length - 1] & -2147483648) == -2147483648;
  640.             }
  641.             bool flag1 = flag;
  642.             while (length > 0 && value[length - 1] == 0)
  643.             {
  644.                 length--;
  645.             }
  646.             if (length != 0)
  647.             {
  648.                 if (length != 1)
  649.                 {
  650.                     if (flag1)
  651.                     {
  652.                         NumericsHelpers.DangerousMakeTwosComplement(value);
  653.                         int num = (int)value.Length;
  654.                         while (num > 0 && value[num - 1] == 0)
  655.                         {
  656.                             num--;
  657.                         }
  658.                         if (num != 1 || value[0] <= 0)
  659.                         {
  660.                             if (num == (int)value.Length)
  661.                             {
  662.                                 this._sign = -1;
  663.                                 this._bits = value;
  664.                                 return;
  665.                             }
  666.                             else
  667.                             {
  668.                                 this._sign = -1;
  669.                                 this._bits = new uint[num];
  670.                                 Array.Copy(value, this._bits, num);
  671.                                 return;
  672.                             }
  673.                         }
  674.                         else
  675.                         {
  676.                             if (value[0] != 1)
  677.                             {
  678.                                 if (value[0] != -2147483648)
  679.                                 {
  680.                                     this._sign = -1 * value[0];
  681.                                     this._bits = null;
  682.                                     return;
  683.                                 }
  684.                                 else
  685.                                 {
  686.                                     *(this) = BigInteger.s_bnMinInt;
  687.                                     return;
  688.                                 }
  689.                             }
  690.                             else
  691.                             {
  692.                                 *(this) = BigInteger.s_bnMinusOneInt;
  693.                                 return;
  694.                             }
  695.                         }
  696.                     }
  697.                     else
  698.                     {
  699.                         if (length == (int)value.Length)
  700.                         {
  701.                             this._sign = 1;
  702.                             this._bits = value;
  703.                             return;
  704.                         }
  705.                         else
  706.                         {
  707.                             this._sign = 1;
  708.                             this._bits = new uint[length];
  709.                             Array.Copy(value, this._bits, length);
  710.                             return;
  711.                         }
  712.                     }
  713.                 }
  714.                 else
  715.                 {
  716.                     if (value[0] >= 0 || flag1)
  717.                     {
  718.                         if (-2147483648 != value[0])
  719.                         {
  720.                             this._sign = value[0];
  721.                             this._bits = null;
  722.                             return;
  723.                         }
  724.                         else
  725.                         {
  726.                             *(this) = BigInteger.s_bnMinInt;
  727.                             return;
  728.                         }
  729.                     }
  730.                     else
  731.                     {
  732.                         this._bits = new uint[1];
  733.                         this._bits[0] = value[0];
  734.                         this._sign = 1;
  735.                         return;
  736.                     }
  737.                 }
  738.             }
  739.             else
  740.             {
  741.                 *(this) = BigInteger.s_bnZeroInt;
  742.                 return;
  743.             }
  744.         }
  745.         else
  746.         {
  747.             throw new ArgumentNullException("value");
  748.         }
  749.     }
  750.  
  751.     public static BigInteger Abs(BigInteger value)
  752.     {
  753.         if (value >= BigInteger.Zero)
  754.         {
  755.             return value;
  756.         }
  757.         else
  758.         {
  759.             return -value;
  760.         }
  761.     }
  762.  
  763.     [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
  764.     public static BigInteger Add(BigInteger left, BigInteger right)
  765.     {
  766.         return left + right;
  767.     }
  768.  
  769.     [Conditional("DEBUG")]
  770.     private void AssertValid()
  771.     {
  772.         if (this._bits != null)
  773.         {
  774.             BigInteger.Length(this._bits);
  775.         }
  776.     }
  777.  
  778.     internal static int BitLengthOfUInt(uint x)
  779.     {
  780.         int num = 0;
  781.         while (x > 0)
  782.         {
  783.             x = x >> 1;
  784.             num++;
  785.         }
  786.         return num;
  787.     }
  788.  
  789.     public static int Compare(BigInteger left, BigInteger right)
  790.     {
  791.         return left.CompareTo(right);
  792.     }
  793.  
  794.     public int CompareTo(long other)
  795.     {
  796.         long num;
  797.         ulong num1;
  798.         if (this._bits != null)
  799.         {
  800.             if (((long)this._sign ^ other) >= (long)0)
  801.             {
  802.                 int num2 = BigInteger.Length(this._bits);
  803.                 int num3 = num2;
  804.                 if (num2 <= 2)
  805.                 {
  806.                     if (other < (long)0)
  807.                     {
  808.                         num = -other;
  809.                     }
  810.                     else
  811.                     {
  812.                         num = other;
  813.                     }
  814.                     ulong num4 = (ulong)num;
  815.                     if (num3 == 2)
  816.                     {
  817.                         num1 = NumericsHelpers.MakeUlong(this._bits[1], this._bits[0]);
  818.                     }
  819.                     else
  820.                     {
  821.                         num1 = (ulong)this._bits[0];
  822.                     }
  823.                     ulong num5 = num1;
  824.                     return this._sign * num5.CompareTo(num4);
  825.                 }
  826.             }
  827.             return this._sign;
  828.         }
  829.         else
  830.         {
  831.             long num6 = (long)this._sign;
  832.             return num6.CompareTo(other);
  833.         }
  834.     }
  835.  
  836.     [CLSCompliant(false)]
  837.     public int CompareTo(ulong other)
  838.     {
  839.         ulong num;
  840.         if (this._sign >= 0)
  841.         {
  842.             if (this._bits != null)
  843.             {
  844.                 int num1 = BigInteger.Length(this._bits);
  845.                 if (num1 <= 2)
  846.                 {
  847.                     if (num1 == 2)
  848.                     {
  849.                         num = NumericsHelpers.MakeUlong(this._bits[1], this._bits[0]);
  850.                     }
  851.                     else
  852.                     {
  853.                         num = (ulong)this._bits[0];
  854.                     }
  855.                     ulong num2 = num;
  856.                     return num2.CompareTo(other);
  857.                 }
  858.                 else
  859.                 {
  860.                     return 1;
  861.                 }
  862.             }
  863.             else
  864.             {
  865.                 ulong num3 = (long)this._sign;
  866.                 return num3.CompareTo(other);
  867.             }
  868.         }
  869.         else
  870.         {
  871.             return -1;
  872.         }
  873.     }
  874.  
  875.     public int CompareTo(BigInteger other)
  876.     {
  877.         if ((this._sign ^ other._sign) >= 0)
  878.         {
  879.             if (this._bits != null)
  880.             {
  881.                 if (other._bits != null)
  882.                 {
  883.                     int num = BigInteger.Length(this._bits);
  884.                     int num1 = num;
  885.                     int num2 = BigInteger.Length(other._bits);
  886.                     int num3 = num2;
  887.                     if (num <= num2)
  888.                     {
  889.                         if (num1 >= num3)
  890.                         {
  891.                             int diffLength = BigInteger.GetDiffLength(this._bits, other._bits, num1);
  892.                             if (diffLength != 0)
  893.                             {
  894.                                 if (this._bits[diffLength - 1] < other._bits[diffLength - 1])
  895.                                 {
  896.                                     return -this._sign;
  897.                                 }
  898.                                 else
  899.                                 {
  900.                                     return this._sign;
  901.                                 }
  902.                             }
  903.                             else
  904.                             {
  905.                                 return 0;
  906.                             }
  907.                         }
  908.                         else
  909.                         {
  910.                             return -this._sign;
  911.                         }
  912.                     }
  913.                 }
  914.                 return this._sign;
  915.             }
  916.             else
  917.             {
  918.                 if (other._bits != null)
  919.                 {
  920.                     return -other._sign;
  921.                 }
  922.                 else
  923.                 {
  924.                     if (this._sign < other._sign)
  925.                     {
  926.                         return -1;
  927.                     }
  928.                     else
  929.                     {
  930.                         if (this._sign > other._sign)
  931.                         {
  932.                             return 1;
  933.                         }
  934.                         else
  935.                         {
  936.                             return 0;
  937.                         }
  938.                     }
  939.                 }
  940.             }
  941.         }
  942.         else
  943.         {
  944.             if (this._sign < 0)
  945.             {
  946.                 return -1;
  947.             }
  948.             else
  949.             {
  950.                 return 1;
  951.             }
  952.         }
  953.     }
  954.  
  955.     public int CompareTo(object obj)
  956.     {
  957.         if (obj != null)
  958.         {
  959.             if (obj as BigInteger != null)
  960.             {
  961.                 return this.CompareTo((BigInteger)obj);
  962.             }
  963.             else
  964.             {
  965.                 throw new ArgumentException(SR.GetString("Argument_MustBeBigInt"));
  966.             }
  967.         }
  968.         else
  969.         {
  970.             return 1;
  971.         }
  972.     }
  973.  
  974.     [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
  975.     public static BigInteger Divide(BigInteger dividend, BigInteger divisor)
  976.     {
  977.         return dividend / divisor;
  978.     }
  979.  
  980.     public static BigInteger DivRem(BigInteger dividend, BigInteger divisor, out BigInteger remainder)
  981.     {
  982.         int num = 1;
  983.         int num1 = 1;
  984.         BigIntegerBuilder bigIntegerBuilder = new BigIntegerBuilder(dividend, ref num);
  985.         BigIntegerBuilder bigIntegerBuilder1 = new BigIntegerBuilder(divisor, ref num1);
  986.         BigIntegerBuilder bigIntegerBuilder2 = new BigIntegerBuilder();
  987.         bigIntegerBuilder.ModDiv(ref bigIntegerBuilder1, ref bigIntegerBuilder2);
  988.         remainder = bigIntegerBuilder.GetInteger(num);
  989.         return bigIntegerBuilder2.GetInteger(num * num1);
  990.     }
  991.  
  992.     public override bool Equals(object obj)
  993.     {
  994.         if (obj as BigInteger != null)
  995.         {
  996.             return this.Equals((BigInteger)obj);
  997.         }
  998.         else
  999.         {
  1000.             return false;
  1001.         }
  1002.     }
  1003.  
  1004.     public bool Equals(long other)
  1005.     {
  1006.         long num;
  1007.         if (this._bits != null)
  1008.         {
  1009.             if (((long)this._sign ^ other) >= (long)0)
  1010.             {
  1011.                 int num1 = BigInteger.Length(this._bits);
  1012.                 int num2 = num1;
  1013.                 if (num1 <= 2)
  1014.                 {
  1015.                     if (other < (long)0)
  1016.                     {
  1017.                         num = -other;
  1018.                     }
  1019.                     else
  1020.                     {
  1021.                         num = other;
  1022.                     }
  1023.                     ulong num3 = (ulong)num;
  1024.                     if (num2 != 1)
  1025.                     {
  1026.                         return NumericsHelpers.MakeUlong(this._bits[1], this._bits[0]) == num3;
  1027.                     }
  1028.                     else
  1029.                     {
  1030.                         return (ulong)this._bits[0] == num3;
  1031.                     }
  1032.                 }
  1033.             }
  1034.             return false;
  1035.         }
  1036.         else
  1037.         {
  1038.             return (long)this._sign == other;
  1039.         }
  1040.     }
  1041.  
  1042.     [CLSCompliant(false)]
  1043.     public bool Equals(ulong other)
  1044.     {
  1045.         if (this._sign >= 0)
  1046.         {
  1047.             if (this._bits != null)
  1048.             {
  1049.                 int num = BigInteger.Length(this._bits);
  1050.                 if (num <= 2)
  1051.                 {
  1052.                     if (num != 1)
  1053.                     {
  1054.                         return NumericsHelpers.MakeUlong(this._bits[1], this._bits[0]) == other;
  1055.                     }
  1056.                     else
  1057.                     {
  1058.                         return (ulong)this._bits[0] == other;
  1059.                     }
  1060.                 }
  1061.                 else
  1062.                 {
  1063.                     return false;
  1064.                 }
  1065.             }
  1066.             else
  1067.             {
  1068.                 return (long)this._sign == other;
  1069.             }
  1070.         }
  1071.         else
  1072.         {
  1073.             return false;
  1074.         }
  1075.     }
  1076.  
  1077.     public bool Equals(BigInteger other)
  1078.     {
  1079.         if (this._sign == other._sign)
  1080.         {
  1081.             if (this._bits != other._bits)
  1082.             {
  1083.                 if (this._bits == null || other._bits == null)
  1084.                 {
  1085.                     return false;
  1086.                 }
  1087.                 else
  1088.                 {
  1089.                     int num = BigInteger.Length(this._bits);
  1090.                     if (num == BigInteger.Length(other._bits))
  1091.                     {
  1092.                         int diffLength = BigInteger.GetDiffLength(this._bits, other._bits, num);
  1093.                         return diffLength == 0;
  1094.                     }
  1095.                     else
  1096.                     {
  1097.                         return false;
  1098.                     }
  1099.                 }
  1100.             }
  1101.             else
  1102.             {
  1103.                 return true;
  1104.             }
  1105.         }
  1106.         else
  1107.         {
  1108.             return false;
  1109.         }
  1110.     }
  1111.  
  1112.     internal static int GetDiffLength(uint[] rgu1, uint[] rgu2, int cu)
  1113.     {
  1114.         int num = cu;
  1115.         do
  1116.         {
  1117.             int num1 = num - 1;
  1118.             num = num1;
  1119.             if (num1 >= 0)
  1120.             {
  1121.                 continue;
  1122.             }
  1123.             return 0;
  1124.         }
  1125.         while (rgu1[num] == rgu2[num]);
  1126.         return num + 1;
  1127.     }
  1128.  
  1129.     public override int GetHashCode()
  1130.     {
  1131.         if (this._bits != null)
  1132.         {
  1133.             int num = this._sign;
  1134.             int num1 = BigInteger.Length(this._bits);
  1135.             while (true)
  1136.             {
  1137.                 int num2 = num1 - 1;
  1138.                 num1 = num2;
  1139.                 if (num2 < 0)
  1140.                 {
  1141.                     break;
  1142.                 }
  1143.                 num = NumericsHelpers.CombineHash(num, this._bits[num1]);
  1144.             }
  1145.             return num;
  1146.         }
  1147.         else
  1148.         {
  1149.             return this._sign;
  1150.         }
  1151.     }
  1152.  
  1153.     private static bool GetPartsForBitManipulation(ref BigInteger x, out uint[] xd, out int xl)
  1154.     {
  1155.         int length;
  1156.         if (x._bits != null)
  1157.         {
  1158.             xd = x._bits;
  1159.         }
  1160.         else
  1161.         {
  1162.             if (x._sign >= 0)
  1163.             {
  1164.                 uint[] numArray = new uint[1];
  1165.                 numArray[0] = x._sign;
  1166.                 xd = numArray;
  1167.             }
  1168.             else
  1169.             {
  1170.                 uint[] numArray1 = new uint[1];
  1171.                 numArray1[0] = -x._sign;
  1172.                 xd = numArray1;
  1173.             }
  1174.         }
  1175.         int& numPointer = xl;
  1176.         if (x._bits == null)
  1177.         {
  1178.             length = 1;
  1179.         }
  1180.         else
  1181.         {
  1182.             length = (int)x._bits.Length;
  1183.         }
  1184.         *(numPointer) = length;
  1185.         return x._sign < 0;
  1186.     }
  1187.  
  1188.     public static BigInteger GreatestCommonDivisor(BigInteger left, BigInteger right)
  1189.     {
  1190.         if (left._sign != 0)
  1191.         {
  1192.             if (right._sign != 0)
  1193.             {
  1194.                 BigIntegerBuilder bigIntegerBuilder = new BigIntegerBuilder(left);
  1195.                 BigIntegerBuilder bigIntegerBuilder1 = new BigIntegerBuilder(right);
  1196.                 BigIntegerBuilder.GCD(ref bigIntegerBuilder, ref bigIntegerBuilder1);
  1197.                 return bigIntegerBuilder.GetInteger(1);
  1198.             }
  1199.             else
  1200.             {
  1201.                 return BigInteger.Abs(left);
  1202.             }
  1203.         }
  1204.         else
  1205.         {
  1206.             return BigInteger.Abs(right);
  1207.         }
  1208.     }
  1209.  
  1210.     internal static int Length(uint[] rgu)
  1211.     {
  1212.         int length = (int)rgu.Length;
  1213.         if (rgu[length - 1] == 0)
  1214.         {
  1215.             return length - 1;
  1216.         }
  1217.         else
  1218.         {
  1219.             return length;
  1220.         }
  1221.     }
  1222.  
  1223.     [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
  1224.     public static double Log(BigInteger value)
  1225.     {
  1226.         return BigInteger.Log(value, 2.71828182845905);
  1227.     }
  1228.  
  1229.     public static double Log(BigInteger value, double baseValue)
  1230.     {
  1231.         if (value._sign < 0 || baseValue == 1)
  1232.         {
  1233.             return double.NaN;
  1234.         }
  1235.         else
  1236.         {
  1237.             if (baseValue != double.PositiveInfinity)
  1238.             {
  1239.                 if (baseValue != 0 || value.IsOne)
  1240.                 {
  1241.                     if (value._bits != null)
  1242.                     {
  1243.                         double num = 0;
  1244.                         double num1 = 0.5;
  1245.                         int num2 = BigInteger.Length(value._bits);
  1246.                         int num3 = BigInteger.BitLengthOfUInt(value._bits[num2 - 1]);
  1247.                         int num4 = (num2 - 1) * 32 + num3;
  1248.                         uint num5 = 1 << (num3 - 1 & 31);
  1249.                         for (int i = num2 - 1; i >= 0; i--)
  1250.                         {
  1251.                             while (num5 != 0)
  1252.                             {
  1253.                                 if ((value._bits[i] & num5) != 0)
  1254.                                 {
  1255.                                     num = num + num1;
  1256.                                 }
  1257.                                 num1 = num1 * 0.5;
  1258.                                 num5 = num5 >> 1;
  1259.                             }
  1260.                             num5 = -2147483648;
  1261.                         }
  1262.                         return (Math.Log(num) + 0.693147180559945 * (double)num4) / Math.Log(baseValue);
  1263.                     }
  1264.                     else
  1265.                     {
  1266.                         return Math.Log((double)value._sign, baseValue);
  1267.                     }
  1268.                 }
  1269.                 else
  1270.                 {
  1271.                     return double.NaN;
  1272.                 }
  1273.             }
  1274.             else
  1275.             {
  1276.                 if (value.IsOne)
  1277.                 {
  1278.                     return 0;
  1279.                 }
  1280.                 else
  1281.                 {
  1282.                     return double.NaN;
  1283.                 }
  1284.             }
  1285.         }
  1286.     }
  1287.  
  1288.     [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
  1289.     public static double Log10(BigInteger value)
  1290.     {
  1291.         return BigInteger.Log(value, 10);
  1292.     }
  1293.  
  1294.     public static BigInteger Max(BigInteger left, BigInteger right)
  1295.     {
  1296.         if (left.CompareTo(right) >= 0)
  1297.         {
  1298.             return left;
  1299.         }
  1300.         else
  1301.         {
  1302.             return right;
  1303.         }
  1304.     }
  1305.  
  1306.     public static BigInteger Min(BigInteger left, BigInteger right)
  1307.     {
  1308.         if (left.CompareTo(right) > 0)
  1309.         {
  1310.             return right;
  1311.         }
  1312.         else
  1313.         {
  1314.             return left;
  1315.         }
  1316.     }
  1317.  
  1318.     public static BigInteger ModPow(BigInteger value, BigInteger exponent, BigInteger modulus)
  1319.     {
  1320.         byte num;
  1321.         if (exponent.Sign >= 0)
  1322.         {
  1323.             int num1 = 1;
  1324.             int num2 = 1;
  1325.             int num3 = 1;
  1326.             bool isEven = exponent.IsEven;
  1327.             BigIntegerBuilder bigIntegerBuilder = new BigIntegerBuilder(BigInteger.One, ref num1);
  1328.             BigIntegerBuilder bigIntegerBuilder1 = new BigIntegerBuilder(value, ref num2);
  1329.             BigIntegerBuilder bigIntegerBuilder2 = new BigIntegerBuilder(modulus, ref num3);
  1330.             BigIntegerBuilder bigIntegerBuilder3 = new BigIntegerBuilder(bigIntegerBuilder1.Size);
  1331.             bigIntegerBuilder.Mod(ref bigIntegerBuilder2);
  1332.             if (exponent._bits != null)
  1333.             {
  1334.                 int num4 = BigInteger.Length(exponent._bits);
  1335.                 for (int i = 0; i < num4 - 1; i++)
  1336.                 {
  1337.                     uint num5 = exponent._bits[i];
  1338.                     BigInteger.ModPowInner32(num5, ref bigIntegerBuilder, ref bigIntegerBuilder1, ref bigIntegerBuilder2, ref bigIntegerBuilder3);
  1339.                 }
  1340.                 BigInteger.ModPowInner(exponent._bits[num4 - 1], ref bigIntegerBuilder, ref bigIntegerBuilder1, ref bigIntegerBuilder2, ref bigIntegerBuilder3);
  1341.             }
  1342.             else
  1343.             {
  1344.                 BigInteger.ModPowInner(exponent._sign, ref bigIntegerBuilder, ref bigIntegerBuilder1, ref bigIntegerBuilder2, ref bigIntegerBuilder3);
  1345.             }
  1346.             BigIntegerBuilder& bigIntegerBuilderPointer = &bigIntegerBuilder;
  1347.             if (value._sign > 0)
  1348.             {
  1349.                 num = 1;
  1350.             }
  1351.             else
  1352.             {
  1353.                 if (isEven)
  1354.                 {
  1355.                     num = 1;
  1356.                 }
  1357.                 else
  1358.                 {
  1359.                     num = -1;
  1360.                 }
  1361.             }
  1362.             return bigIntegerBuilderPointer.GetInteger(num);
  1363.         }
  1364.         else
  1365.         {
  1366.             throw new ArgumentOutOfRangeException("exponent", SR.GetString("ArgumentOutOfRange_MustBeNonNeg"));
  1367.         }
  1368.     }
  1369.  
  1370.     private static void ModPowInner(uint exp, ref BigIntegerBuilder regRes, ref BigIntegerBuilder regVal, ref BigIntegerBuilder regMod, ref BigIntegerBuilder regTmp)
  1371.     {
  1372.         while (exp != 0)
  1373.         {
  1374.             if ((exp & 1) == 1)
  1375.             {
  1376.                 BigInteger.ModPowUpdateResult(ref regRes, ref regVal, ref regMod, ref regTmp);
  1377.             }
  1378.             if (exp != 1)
  1379.             {
  1380.                 BigInteger.ModPowSquareModValue(ref regVal, ref regMod, ref regTmp);
  1381.                 exp = exp >> 1;
  1382.             }
  1383.             else
  1384.             {
  1385.                 return;
  1386.             }
  1387.         }
  1388.     }
  1389.  
  1390.     private static void ModPowInner32(uint exp, ref BigIntegerBuilder regRes, ref BigIntegerBuilder regVal, ref BigIntegerBuilder regMod, ref BigIntegerBuilder regTmp)
  1391.     {
  1392.         for (int i = 0; i < 32; i++)
  1393.         {
  1394.             if ((exp & 1) == 1)
  1395.             {
  1396.                 BigInteger.ModPowUpdateResult(ref regRes, ref regVal, ref regMod, ref regTmp);
  1397.             }
  1398.             BigInteger.ModPowSquareModValue(ref regVal, ref regMod, ref regTmp);
  1399.             exp = exp >> 1;
  1400.         }
  1401.     }
  1402.  
  1403.     private static void ModPowSquareModValue(ref BigIntegerBuilder regVal, ref BigIntegerBuilder regMod, ref BigIntegerBuilder regTmp)
  1404.     {
  1405.         NumericsHelpers.<BigIntegerBuilder>(ref regVal, ref regTmp);
  1406.         regVal.Mul(ref regTmp, ref regTmp);
  1407.         regVal.Mod(ref regMod);
  1408.     }
  1409.  
  1410.     private static void ModPowUpdateResult(ref BigIntegerBuilder regRes, ref BigIntegerBuilder regVal, ref BigIntegerBuilder regMod, ref BigIntegerBuilder regTmp)
  1411.     {
  1412.         NumericsHelpers.<BigIntegerBuilder>(ref regRes, ref regTmp);
  1413.         regRes.Mul(ref regTmp, ref regVal);
  1414.         regRes.Mod(ref regMod);
  1415.     }
  1416.  
  1417.     private static void MulLower(ref uint uHiRes, ref int cuRes, uint uHiMul, int cuMul)
  1418.     {
  1419.         ulong num = (ulong)uHiRes * (ulong)uHiMul;
  1420.         uint hi = NumericsHelpers.GetHi(num);
  1421.         if (hi == 0)
  1422.         {
  1423.             uHiRes = NumericsHelpers.GetLo(num);
  1424.             cuRes = cuRes + cuMul - 1;
  1425.             return;
  1426.         }
  1427.         else
  1428.         {
  1429.             uHiRes = hi;
  1430.             cuRes = cuRes + cuMul;
  1431.             return;
  1432.         }
  1433.     }
  1434.  
  1435.     [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
  1436.     public static BigInteger Multiply(BigInteger left, BigInteger right)
  1437.     {
  1438.         return left * right;
  1439.     }
  1440.  
  1441.     private static void MulUpper(ref uint uHiRes, ref int cuRes, uint uHiMul, int cuMul)
  1442.     {
  1443.         ulong num = (ulong)uHiRes * (ulong)uHiMul;
  1444.         uint hi = NumericsHelpers.GetHi(num);
  1445.         if (hi == 0)
  1446.         {
  1447.             uHiRes = NumericsHelpers.GetLo(num);
  1448.             cuRes = cuRes + cuMul - 1;
  1449.             return;
  1450.         }
  1451.         else
  1452.         {
  1453.             if (NumericsHelpers.GetLo(num) != 0)
  1454.             {
  1455.                 int num1 = hi + 1;
  1456.                 hi = (uint)num1;
  1457.                 if (num1 == 0)
  1458.                 {
  1459.                     hi = 1;
  1460.                     cuRes = cuRes + 1;
  1461.                 }
  1462.             }
  1463.             uHiRes = hi;
  1464.             cuRes = cuRes + cuMul;
  1465.             return;
  1466.         }
  1467.     }
  1468.  
  1469.     [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
  1470.     public static BigInteger Negate(BigInteger value)
  1471.     {
  1472.         return -value;
  1473.     }
  1474.  
  1475.     public static BigInteger operator +(BigInteger left, BigInteger right)
  1476.     {
  1477.         if (!right.IsZero)
  1478.         {
  1479.             if (!left.IsZero)
  1480.             {
  1481.                 int num = 1;
  1482.                 int num1 = 1;
  1483.                 BigIntegerBuilder bigIntegerBuilder = new BigIntegerBuilder(left, ref num);
  1484.                 BigIntegerBuilder bigIntegerBuilder1 = new BigIntegerBuilder(right, ref num1);
  1485.                 if (num != num1)
  1486.                 {
  1487.                     bigIntegerBuilder.Sub(ref num, ref bigIntegerBuilder1);
  1488.                 }
  1489.                 else
  1490.                 {
  1491.                     bigIntegerBuilder.Add(ref bigIntegerBuilder1);
  1492.                 }
  1493.                 return bigIntegerBuilder.GetInteger(num);
  1494.             }
  1495.             else
  1496.             {
  1497.                 return right;
  1498.             }
  1499.         }
  1500.         else
  1501.         {
  1502.             return left;
  1503.         }
  1504.     }
  1505.  
  1506.     public static BigInteger operator &(BigInteger left, BigInteger right)
  1507.     {
  1508.         byte num;
  1509.         byte num1;
  1510.         uint num2;
  1511.         uint num3;
  1512.         if (left.IsZero || right.IsZero)
  1513.         {
  1514.             return BigInteger.Zero;
  1515.         }
  1516.         else
  1517.         {
  1518.             uint[] uInt32Array = left.ToUInt32Array();
  1519.             uint[] numArray = right.ToUInt32Array();
  1520.             uint[] numArray1 = new uint[Math.Max((int)uInt32Array.Length, (int)numArray.Length)];
  1521.             if (left._sign < 0)
  1522.             {
  1523.                 num = -1;
  1524.             }
  1525.             else
  1526.             {
  1527.                 num = 0;
  1528.             }
  1529.             uint num4 = (uint)num;
  1530.             if (right._sign < 0)
  1531.             {
  1532.                 num1 = -1;
  1533.             }
  1534.             else
  1535.             {
  1536.                 num1 = 0;
  1537.             }
  1538.             uint num5 = (uint)num1;
  1539.             for (int i = 0; i < (int)numArray1.Length; i++)
  1540.             {
  1541.                 if (i < (int)uInt32Array.Length)
  1542.                 {
  1543.                     num2 = uInt32Array[i];
  1544.                 }
  1545.                 else
  1546.                 {
  1547.                     num2 = num4;
  1548.                 }
  1549.                 uint num6 = num2;
  1550.                 if (i < (int)numArray.Length)
  1551.                 {
  1552.                     num3 = numArray[i];
  1553.                 }
  1554.                 else
  1555.                 {
  1556.                     num3 = num5;
  1557.                 }
  1558.                 uint num7 = num3;
  1559.                 numArray1[i] = num6 & num7;
  1560.             }
  1561.             return new BigInteger(numArray1);
  1562.         }
  1563.     }
  1564.  
  1565.     public static BigInteger operator |(BigInteger left, BigInteger right)
  1566.     {
  1567.         byte num;
  1568.         byte num1;
  1569.         uint num2;
  1570.         uint num3;
  1571.         if (!left.IsZero)
  1572.         {
  1573.             if (!right.IsZero)
  1574.             {
  1575.                 uint[] uInt32Array = left.ToUInt32Array();
  1576.                 uint[] numArray = right.ToUInt32Array();
  1577.                 uint[] numArray1 = new uint[Math.Max((int)uInt32Array.Length, (int)numArray.Length)];
  1578.                 if (left._sign < 0)
  1579.                 {
  1580.                     num = -1;
  1581.                 }
  1582.                 else
  1583.                 {
  1584.                     num = 0;
  1585.                 }
  1586.                 uint num4 = (uint)num;
  1587.                 if (right._sign < 0)
  1588.                 {
  1589.                     num1 = -1;
  1590.                 }
  1591.                 else
  1592.                 {
  1593.                     num1 = 0;
  1594.                 }
  1595.                 uint num5 = (uint)num1;
  1596.                 for (int i = 0; i < (int)numArray1.Length; i++)
  1597.                 {
  1598.                     if (i < (int)uInt32Array.Length)
  1599.                     {
  1600.                         num2 = uInt32Array[i];
  1601.                     }
  1602.                     else
  1603.                     {
  1604.                         num2 = num4;
  1605.                     }
  1606.                     uint num6 = num2;
  1607.                     if (i < (int)numArray.Length)
  1608.                     {
  1609.                         num3 = numArray[i];
  1610.                     }
  1611.                     else
  1612.                     {
  1613.                         num3 = num5;
  1614.                     }
  1615.                     uint num7 = num3;
  1616.                     numArray1[i] = num6 | num7;
  1617.                 }
  1618.                 return new BigInteger(numArray1);
  1619.             }
  1620.             else
  1621.             {
  1622.                 return left;
  1623.             }
  1624.         }
  1625.         else
  1626.         {
  1627.             return right;
  1628.         }
  1629.     }
  1630.  
  1631.     public static BigInteger operator --(BigInteger value)
  1632.     {
  1633.         return value - BigInteger.One;
  1634.     }
  1635.  
  1636.     public static BigInteger operator /(BigInteger dividend, BigInteger divisor)
  1637.     {
  1638.         int num = 1;
  1639.         BigIntegerBuilder bigIntegerBuilder = new BigIntegerBuilder(dividend, ref num);
  1640.         BigIntegerBuilder bigIntegerBuilder1 = new BigIntegerBuilder(divisor, ref num);
  1641.         bigIntegerBuilder.Div(ref bigIntegerBuilder1);
  1642.         return bigIntegerBuilder.GetInteger(num);
  1643.     }
  1644.  
  1645.     public static bool operator ==(BigInteger left, BigInteger right)
  1646.     {
  1647.         return left.Equals(right);
  1648.     }
  1649.  
  1650.     public static bool operator ==(BigInteger left, long right)
  1651.     {
  1652.         return left.Equals(right);
  1653.     }
  1654.  
  1655.     public static bool operator ==(long left, BigInteger right)
  1656.     {
  1657.         return right.Equals(left);
  1658.     }
  1659.  
  1660.     [CLSCompliant(false)]
  1661.     public static bool operator ==(BigInteger left, ulong right)
  1662.     {
  1663.         return left.Equals(right);
  1664.     }
  1665.  
  1666.     [CLSCompliant(false)]
  1667.     public static bool operator ==(ulong left, BigInteger right)
  1668.     {
  1669.         return right.Equals(left);
  1670.     }
  1671.  
  1672.     public static BigInteger operator ^(BigInteger left, BigInteger right)
  1673.     {
  1674.         byte num;
  1675.         byte num1;
  1676.         uint num2;
  1677.         uint num3;
  1678.         uint[] uInt32Array = left.ToUInt32Array();
  1679.         uint[] numArray = right.ToUInt32Array();
  1680.         uint[] numArray1 = new uint[Math.Max((int)uInt32Array.Length, (int)numArray.Length)];
  1681.         if (left._sign < 0)
  1682.         {
  1683.             num = -1;
  1684.         }
  1685.         else
  1686.         {
  1687.             num = 0;
  1688.         }
  1689.         uint num4 = (uint)num;
  1690.         if (right._sign < 0)
  1691.         {
  1692.             num1 = -1;
  1693.         }
  1694.         else
  1695.         {
  1696.             num1 = 0;
  1697.         }
  1698.         uint num5 = (uint)num1;
  1699.         for (int i = 0; i < (int)numArray1.Length; i++)
  1700.         {
  1701.             if (i < (int)uInt32Array.Length)
  1702.             {
  1703.                 num2 = uInt32Array[i];
  1704.             }
  1705.             else
  1706.             {
  1707.                 num2 = num4;
  1708.             }
  1709.             uint num6 = num2;
  1710.             if (i < (int)numArray.Length)
  1711.             {
  1712.                 num3 = numArray[i];
  1713.             }
  1714.             else
  1715.             {
  1716.                 num3 = num5;
  1717.             }
  1718.             uint num7 = num3;
  1719.             numArray1[i] = num6 ^ num7;
  1720.         }
  1721.         return new BigInteger(numArray1);
  1722.     }
  1723.  
  1724.     public static explicit operator BigInteger(float value)
  1725.     {
  1726.         return new BigInteger(value);
  1727.     }
  1728.  
  1729.     public static explicit operator BigInteger(double value)
  1730.     {
  1731.         return new BigInteger(value);
  1732.     }
  1733.  
  1734.     public static explicit operator BigInteger(decimal value)
  1735.     {
  1736.         return new BigInteger(value);
  1737.     }
  1738.  
  1739.     public static explicit operator Byte(BigInteger value)
  1740.     {
  1741.         return (byte)((int)value);
  1742.     }
  1743.  
  1744.     [CLSCompliant(false)]
  1745.     public static explicit operator SByte(BigInteger value)
  1746.     {
  1747.         return (sbyte)((int)value);
  1748.     }
  1749.  
  1750.     public static explicit operator Int16(BigInteger value)
  1751.     {
  1752.         return (short)((int)value);
  1753.     }
  1754.  
  1755.     [CLSCompliant(false)]
  1756.     public static explicit operator UInt16(BigInteger value)
  1757.     {
  1758.         return (ushort)((int)value);
  1759.     }
  1760.  
  1761.     public static explicit operator Int32(BigInteger value)
  1762.     {
  1763.         if (value._bits != null)
  1764.         {
  1765.             if (BigInteger.Length(value._bits) <= 1)
  1766.             {
  1767.                 if (value._sign <= 0)
  1768.                 {
  1769.                     if (value._bits[0] <= -2147483648)
  1770.                     {
  1771.                         return -value._bits[0];
  1772.                     }
  1773.                     else
  1774.                     {
  1775.                         throw new OverflowException(SR.GetString("Overflow_Int32"));
  1776.                     }
  1777.                 }
  1778.                 else
  1779.                 {
  1780.                     return (void*)((int)value._bits[0]);
  1781.                 }
  1782.             }
  1783.             else
  1784.             {
  1785.                 throw new OverflowException(SR.GetString("Overflow_Int32"));
  1786.             }
  1787.         }
  1788.         else
  1789.         {
  1790.             return value._sign;
  1791.         }
  1792.     }
  1793.  
  1794.     [CLSCompliant(false)]
  1795.     public static explicit operator UInt32(BigInteger value)
  1796.     {
  1797.         if (value._bits != null)
  1798.         {
  1799.             if (BigInteger.Length(value._bits) > 1 || value._sign < 0)
  1800.             {
  1801.                 throw new OverflowException(SR.GetString("Overflow_UInt32"));
  1802.             }
  1803.             else
  1804.             {
  1805.                 return value._bits[0];
  1806.             }
  1807.         }
  1808.         else
  1809.         {
  1810.             return (uint)value._sign;
  1811.         }
  1812.     }
  1813.  
  1814.     public static explicit operator Int64(BigInteger value)
  1815.     {
  1816.         ulong num;
  1817.         ulong num1;
  1818.         if (value._bits != null)
  1819.         {
  1820.             int num2 = BigInteger.Length(value._bits);
  1821.             if (num2 <= 2)
  1822.             {
  1823.                 if (num2 <= 1)
  1824.                 {
  1825.                     num = (ulong)value._bits[0];
  1826.                 }
  1827.                 else
  1828.                 {
  1829.                     num = NumericsHelpers.MakeUlong(value._bits[1], value._bits[0]);
  1830.                 }
  1831.                 if (value._sign > 0)
  1832.                 {
  1833.                     num1 = num;
  1834.                 }
  1835.                 else
  1836.                 {
  1837.                     num1 = -num;
  1838.                 }
  1839.                 long num3 = (long)num1;
  1840.                 if ((num3 <= (long)0 || value._sign <= 0) && (num3 >= (long)0 || value._sign >= 0))
  1841.                 {
  1842.                     throw new OverflowException(SR.GetString("Overflow_Int64"));
  1843.                 }
  1844.                 else
  1845.                 {
  1846.                     return num3;
  1847.                 }
  1848.             }
  1849.             else
  1850.             {
  1851.                 throw new OverflowException(SR.GetString("Overflow_Int64"));
  1852.             }
  1853.         }
  1854.         else
  1855.         {
  1856.             return (long)value._sign;
  1857.         }
  1858.     }
  1859.  
  1860.     [CLSCompliant(false)]
  1861.     public static explicit operator UInt64(BigInteger value)
  1862.     {
  1863.         if (value._bits != null)
  1864.         {
  1865.             int num = BigInteger.Length(value._bits);
  1866.             if (num > 2 || value._sign < 0)
  1867.             {
  1868.                 throw new OverflowException(SR.GetString("Overflow_UInt64"));
  1869.             }
  1870.             else
  1871.             {
  1872.                 if (num <= 1)
  1873.                 {
  1874.                     return (ulong)value._bits[0];
  1875.                 }
  1876.                 else
  1877.                 {
  1878.                     return NumericsHelpers.MakeUlong(value._bits[1], value._bits[0]);
  1879.                 }
  1880.             }
  1881.         }
  1882.         else
  1883.         {
  1884.             return (ulong)value._sign;
  1885.         }
  1886.     }
  1887.  
  1888.     public static explicit operator Single(BigInteger value)
  1889.     {
  1890.         return (float)((double)((double)value));
  1891.     }
  1892.  
  1893.     public static explicit operator Double(BigInteger value)
  1894.     {
  1895.         ulong num = 0L;
  1896.         int num1 = 0;
  1897.         if (value._bits != null)
  1898.         {
  1899.             int num2 = 1;
  1900.             BigIntegerBuilder bigIntegerBuilder = new BigIntegerBuilder(value, ref num2);
  1901.             bigIntegerBuilder.GetApproxParts(out num1, out num);
  1902.             return NumericsHelpers.GetDoubleFromParts(num2, num1, num);
  1903.         }
  1904.         else
  1905.         {
  1906.             return (double)value._sign;
  1907.         }
  1908.     }
  1909.  
  1910.     public static explicit operator Decimal(BigInteger value)
  1911.     {
  1912.         if (value._bits != null)
  1913.         {
  1914.             int num = BigInteger.Length(value._bits);
  1915.             if (num <= 3)
  1916.             {
  1917.                 int num1 = 0;
  1918.                 int num2 = 0;
  1919.                 int num3 = 0;
  1920.                 if (num > 2)
  1921.                 {
  1922.                     num3 = value._bits[2];
  1923.                 }
  1924.                 if (num > 1)
  1925.                 {
  1926.                     num2 = value._bits[1];
  1927.                 }
  1928.                 if (num > 0)
  1929.                 {
  1930.                     num1 = value._bits[0];
  1931.                 }
  1932.                 return new decimal(num1, num2, num3, value._sign < 0, 0);
  1933.             }
  1934.             else
  1935.             {
  1936.                 throw new OverflowException(SR.GetString("Overflow_Decimal"));
  1937.             }
  1938.         }
  1939.         else
  1940.         {
  1941.             return value._sign;
  1942.         }
  1943.     }
  1944.  
  1945.     public static bool operator >(BigInteger left, BigInteger right)
  1946.     {
  1947.         return left.CompareTo(right) > 0;
  1948.     }
  1949.  
  1950.     public static bool operator >(BigInteger left, long right)
  1951.     {
  1952.         return left.CompareTo(right) > 0;
  1953.     }
  1954.  
  1955.     public static bool operator >(long left, BigInteger right)
  1956.     {
  1957.         return right.CompareTo(left) < 0;
  1958.     }
  1959.  
  1960.     [CLSCompliant(false)]
  1961.     public static bool operator >(BigInteger left, ulong right)
  1962.     {
  1963.         return left.CompareTo(right) > 0;
  1964.     }
  1965.  
  1966.     [CLSCompliant(false)]
  1967.     public static bool operator >(ulong left, BigInteger right)
  1968.     {
  1969.         return right.CompareTo(left) < 0;
  1970.     }
  1971.  
  1972.     public static bool operator >=(BigInteger left, BigInteger right)
  1973.     {
  1974.         return left.CompareTo(right) >= 0;
  1975.     }
  1976.  
  1977.     public static bool operator >=(BigInteger left, long right)
  1978.     {
  1979.         return left.CompareTo(right) >= 0;
  1980.     }
  1981.  
  1982.     public static bool operator >=(long left, BigInteger right)
  1983.     {
  1984.         return right.CompareTo(left) <= 0;
  1985.     }
  1986.  
  1987.     [CLSCompliant(false)]
  1988.     public static bool operator >=(BigInteger left, ulong right)
  1989.     {
  1990.         return left.CompareTo(right) >= 0;
  1991.     }
  1992.  
  1993.     [CLSCompliant(false)]
  1994.     public static bool operator >=(ulong left, BigInteger right)
  1995.     {
  1996.         return right.CompareTo(left) <= 0;
  1997.     }
  1998.  
  1999.     public static implicit operator BigInteger(byte value)
  2000.     {
  2001.         return new BigInteger(value);
  2002.     }
  2003.  
  2004.     [CLSCompliant(false)]
  2005.     public static implicit operator BigInteger(sbyte value)
  2006.     {
  2007.         return new BigInteger(value);
  2008.     }
  2009.  
  2010.     public static implicit operator BigInteger(short value)
  2011.     {
  2012.         return new BigInteger(value);
  2013.     }
  2014.  
  2015.     [CLSCompliant(false)]
  2016.     public static implicit operator BigInteger(ushort value)
  2017.     {
  2018.         return new BigInteger(value);
  2019.     }
  2020.  
  2021.     public static implicit operator BigInteger(int value)
  2022.     {
  2023.         return new BigInteger(value);
  2024.     }
  2025.  
  2026.     [CLSCompliant(false)]
  2027.     public static implicit operator BigInteger(uint value)
  2028.     {
  2029.         return new BigInteger(value);
  2030.     }
  2031.  
  2032.     public static implicit operator BigInteger(long value)
  2033.     {
  2034.         return new BigInteger(value);
  2035.     }
  2036.  
  2037.     [CLSCompliant(false)]
  2038.     public static implicit operator BigInteger(ulong value)
  2039.     {
  2040.         return new BigInteger(value);
  2041.     }
  2042.  
  2043.     public static BigInteger operator ++(BigInteger value)
  2044.     {
  2045.         return value + BigInteger.One;
  2046.     }
  2047.  
  2048.     public static bool operator !=(BigInteger left, BigInteger right)
  2049.     {
  2050.         return !left.Equals(right);
  2051.     }
  2052.  
  2053.     public static bool operator !=(BigInteger left, long right)
  2054.     {
  2055.         return !left.Equals(right);
  2056.     }
  2057.  
  2058.     public static bool operator !=(long left, BigInteger right)
  2059.     {
  2060.         return !right.Equals(left);
  2061.     }
  2062.  
  2063.     [CLSCompliant(false)]
  2064.     public static bool operator !=(BigInteger left, ulong right)
  2065.     {
  2066.         return !left.Equals(right);
  2067.     }
  2068.  
  2069.     [CLSCompliant(false)]
  2070.     public static bool operator !=(ulong left, BigInteger right)
  2071.     {
  2072.         return !right.Equals(left);
  2073.     }
  2074.  
  2075.     public static BigInteger operator <<(BigInteger value, int shift)
  2076.     {
  2077.         uint[] numArray = 0;
  2078.         int num = 0;
  2079.         if (shift != 0)
  2080.         {
  2081.             if (shift != -2147483648)
  2082.             {
  2083.                 if (shift >= 0)
  2084.                 {
  2085.                     int num1 = shift / 32;
  2086.                     int num2 = shift - num1 * 32;
  2087.                     bool partsForBitManipulation = BigInteger.GetPartsForBitManipulation(ref value, out numArray, out num);
  2088.                     int num3 = num + num1 + 1;
  2089.                     uint[] numArray1 = new uint[num3];
  2090.                     if (num2 != 0)
  2091.                     {
  2092.                         int num4 = 32 - num2;
  2093.                         uint num5 = 0;
  2094.                         for (int i = 0; i < num; i++)
  2095.                         {
  2096.                             uint num6 = numArray[i];
  2097.                             numArray1[i + num1] = num6 << (num2 & 31) | num5;
  2098.                             num5 = num6 >> (num4 & 31);
  2099.                         }
  2100.                         numArray1[i + num1] = num5;
  2101.                     }
  2102.                     else
  2103.                     {
  2104.                         for (int j = 0; j < num; j++)
  2105.                         {
  2106.                             numArray1[j + num1] = numArray[j];
  2107.                         }
  2108.                     }
  2109.                     return new BigInteger(numArray1, partsForBitManipulation);
  2110.                 }
  2111.                 else
  2112.                 {
  2113.                     return value >> -shift;
  2114.                 }
  2115.             }
  2116.             else
  2117.             {
  2118.                 return value >> 2147483647 >> 1;
  2119.             }
  2120.         }
  2121.         else
  2122.         {
  2123.             return value;
  2124.         }
  2125.     }
  2126.  
  2127.     public static bool operator <(BigInteger left, BigInteger right)
  2128.     {
  2129.         return left.CompareTo(right) < 0;
  2130.     }
  2131.  
  2132.     public static bool operator <(BigInteger left, long right)
  2133.     {
  2134.         return left.CompareTo(right) < 0;
  2135.     }
  2136.  
  2137.     public static bool operator <(long left, BigInteger right)
  2138.     {
  2139.         return right.CompareTo(left) > 0;
  2140.     }
  2141.  
  2142.     [CLSCompliant(false)]
  2143.     public static bool operator <(BigInteger left, ulong right)
  2144.     {
  2145.         return left.CompareTo(right) < 0;
  2146.     }
  2147.  
  2148.     [CLSCompliant(false)]
  2149.     public static bool operator <(ulong left, BigInteger right)
  2150.     {
  2151.         return right.CompareTo(left) > 0;
  2152.     }
  2153.  
  2154.     public static bool operator <=(BigInteger left, BigInteger right)
  2155.     {
  2156.         return left.CompareTo(right) <= 0;
  2157.     }
  2158.  
  2159.     public static bool operator <=(BigInteger left, long right)
  2160.     {
  2161.         return left.CompareTo(right) <= 0;
  2162.     }
  2163.  
  2164.     public static bool operator <=(long left, BigInteger right)
  2165.     {
  2166.         return right.CompareTo(left) >= 0;
  2167.     }
  2168.  
  2169.     [CLSCompliant(false)]
  2170.     public static bool operator <=(BigInteger left, ulong right)
  2171.     {
  2172.         return left.CompareTo(right) <= 0;
  2173.     }
  2174.  
  2175.     [CLSCompliant(false)]
  2176.     public static bool operator <=(ulong left, BigInteger right)
  2177.     {
  2178.         return right.CompareTo(left) >= 0;
  2179.     }
  2180.  
  2181.     public static BigInteger operator %(BigInteger dividend, BigInteger divisor)
  2182.     {
  2183.         int num = 1;
  2184.         int num1 = 1;
  2185.         BigIntegerBuilder bigIntegerBuilder = new BigIntegerBuilder(dividend, ref num);
  2186.         BigIntegerBuilder bigIntegerBuilder1 = new BigIntegerBuilder(divisor, ref num1);
  2187.         bigIntegerBuilder.Mod(ref bigIntegerBuilder1);
  2188.         return bigIntegerBuilder.GetInteger(num);
  2189.     }
  2190.  
  2191.     public static BigInteger operator *(BigInteger left, BigInteger right)
  2192.     {
  2193.         int num = 1;
  2194.         BigIntegerBuilder bigIntegerBuilder = new BigIntegerBuilder(left, ref num);
  2195.         BigIntegerBuilder bigIntegerBuilder1 = new BigIntegerBuilder(right, ref num);
  2196.         bigIntegerBuilder.Mul(ref bigIntegerBuilder1);
  2197.         return bigIntegerBuilder.GetInteger(num);
  2198.     }
  2199.  
  2200.     public static BigInteger operator ~(BigInteger value)
  2201.     {
  2202.         return -(value + BigInteger.One);
  2203.     }
  2204.  
  2205.     public static BigInteger operator >>(BigInteger value, int shift)
  2206.     {
  2207.         uint[] numArray = 0;
  2208.         int num = 0;
  2209.         if (shift != 0)
  2210.         {
  2211.             if (shift != -2147483648)
  2212.             {
  2213.                 if (shift >= 0)
  2214.                 {
  2215.                     int num1 = shift / 32;
  2216.                     int num2 = shift - num1 * 32;
  2217.                     bool partsForBitManipulation = BigInteger.GetPartsForBitManipulation(ref value, out numArray, out num);
  2218.                     if (partsForBitManipulation)
  2219.                     {
  2220.                         if (shift < 32 * num)
  2221.                         {
  2222.                             uint[] numArray1 = new uint[num];
  2223.                             Array.Copy(numArray, numArray1, num);
  2224.                             numArray = numArray1;
  2225.                             NumericsHelpers.DangerousMakeTwosComplement(numArray);
  2226.                         }
  2227.                         else
  2228.                         {
  2229.                             return BigInteger.MinusOne;
  2230.                         }
  2231.                     }
  2232.                     int num3 = num - num1;
  2233.                     if (num3 < 0)
  2234.                     {
  2235.                         num3 = 0;
  2236.                     }
  2237.                     uint[] numArray2 = new uint[num3];
  2238.                     if (num2 != 0)
  2239.                     {
  2240.                         int num4 = 32 - num2;
  2241.                         uint num5 = 0;
  2242.                         for (int i = num - 1; i >= num1; i--)
  2243.                         {
  2244.                             uint num6 = numArray[i];
  2245.                             if (!partsForBitManipulation || i != num - 1)
  2246.                             {
  2247.                                 numArray2[i - num1] = num6 >> (num2 & 31) | num5;
  2248.                             }
  2249.                             else
  2250.                             {
  2251.                                 numArray2[i - num1] = num6 >> (num2 & 31) | -1 << (num4 & 31);
  2252.                             }
  2253.                             num5 = num6 << (num4 & 31);
  2254.                         }
  2255.                     }
  2256.                     else
  2257.                     {
  2258.                         for (int j = num - 1; j >= num1; j--)
  2259.                         {
  2260.                             numArray2[j - num1] = numArray[j];
  2261.                         }
  2262.                     }
  2263.                     if (partsForBitManipulation)
  2264.                     {
  2265.                         NumericsHelpers.DangerousMakeTwosComplement(numArray2);
  2266.                     }
  2267.                     return new BigInteger(numArray2, partsForBitManipulation);
  2268.                 }
  2269.                 else
  2270.                 {
  2271.                     return value << -shift;
  2272.                 }
  2273.             }
  2274.             else
  2275.             {
  2276.                 return value << 2147483647 << 1;
  2277.             }
  2278.         }
  2279.         else
  2280.         {
  2281.             return value;
  2282.         }
  2283.     }
  2284.  
  2285.     public static BigInteger operator -(BigInteger left, BigInteger right)
  2286.     {
  2287.         if (!right.IsZero)
  2288.         {
  2289.             if (!left.IsZero)
  2290.             {
  2291.                 int num = 1;
  2292.                 int num1 = -1;
  2293.                 BigIntegerBuilder bigIntegerBuilder = new BigIntegerBuilder(left, ref num);
  2294.                 BigIntegerBuilder bigIntegerBuilder1 = new BigIntegerBuilder(right, ref num1);
  2295.                 if (num != num1)
  2296.                 {
  2297.                     bigIntegerBuilder.Sub(ref num, ref bigIntegerBuilder1);
  2298.                 }
  2299.                 else
  2300.                 {
  2301.                     bigIntegerBuilder.Add(ref bigIntegerBuilder1);
  2302.                 }
  2303.                 return bigIntegerBuilder.GetInteger(num);
  2304.             }
  2305.             else
  2306.             {
  2307.                 return -right;
  2308.             }
  2309.         }
  2310.         else
  2311.         {
  2312.             return left;
  2313.         }
  2314.     }
  2315.  
  2316.     public static BigInteger operator -(BigInteger value)
  2317.     {
  2318.         value._sign = -value._sign;
  2319.         return value;
  2320.     }
  2321.  
  2322.     public static BigInteger operator +(BigInteger value)
  2323.     {
  2324.         return value;
  2325.     }
  2326.  
  2327.     public static BigInteger Parse(string value)
  2328.     {
  2329.         return BigNumber.ParseBigInteger(value, NumberStyles.Integer, NumberFormatInfo.CurrentInfo);
  2330.     }
  2331.  
  2332.     public static BigInteger Parse(string value, NumberStyles style)
  2333.     {
  2334.         return BigNumber.ParseBigInteger(value, style, NumberFormatInfo.CurrentInfo);
  2335.     }
  2336.  
  2337.     public static BigInteger Parse(string value, IFormatProvider provider)
  2338.     {
  2339.         return BigNumber.ParseBigInteger(value, NumberStyles.Integer, NumberFormatInfo.GetInstance(provider));
  2340.     }
  2341.  
  2342.     public static BigInteger Parse(string value, NumberStyles style, IFormatProvider provider)
  2343.     {
  2344.         return BigNumber.ParseBigInteger(value, style, NumberFormatInfo.GetInstance(provider));
  2345.     }
  2346.  
  2347.     public static BigInteger Pow(BigInteger value, int exponent)
  2348.     {
  2349.         if (exponent >= 0)
  2350.         {
  2351.             if (exponent != 0)
  2352.             {
  2353.                 if (exponent != 1)
  2354.                 {
  2355.                     if (value._bits == null)
  2356.                     {
  2357.                         if (value._sign != 1)
  2358.                         {
  2359.                             if (value._sign != -1)
  2360.                             {
  2361.                                 if (value._sign == 0)
  2362.                                 {
  2363.                                     return value;
  2364.                                 }
  2365.                             }
  2366.                             else
  2367.                             {
  2368.                                 if ((exponent & 1) != 0)
  2369.                                 {
  2370.                                     return value;
  2371.                                 }
  2372.                                 else
  2373.                                 {
  2374.                                     return 1;
  2375.                                 }
  2376.                             }
  2377.                         }
  2378.                         else
  2379.                         {
  2380.                             return value;
  2381.                         }
  2382.                     }
  2383.                     int num = 1;
  2384.                     BigIntegerBuilder bigIntegerBuilder = new BigIntegerBuilder(value, ref num);
  2385.                     int size = bigIntegerBuilder.Size;
  2386.                     int num1 = size;
  2387.                     uint high = bigIntegerBuilder.High;
  2388.                     uint num2 = high + 1;
  2389.                     if (num2 == 0)
  2390.                     {
  2391.                         num1++;
  2392.                         num2 = 1;
  2393.                     }
  2394.                     int num3 = 1;
  2395.                     int num4 = 1;
  2396.                     uint num5 = 1;
  2397.                     uint num6 = 1;
  2398.                     int num7 = exponent;
  2399.                     while (true)
  2400.                     {
  2401.                         if ((num7 & 1) != 0)
  2402.                         {
  2403.                             BigInteger.MulUpper(ref num6, ref num4, num2, num1);
  2404.                             BigInteger.MulLower(ref num5, ref num3, high, size);
  2405.                         }
  2406.                         int num8 = num7 >> 1;
  2407.                         num7 = num8;
  2408.                         if (num8 == 0)
  2409.                         {
  2410.                             break;
  2411.                         }
  2412.                         BigInteger.MulUpper(ref num2, ref num1, num2, num1);
  2413.                         BigInteger.MulLower(ref high, ref size, high, size);
  2414.                     }
  2415.                     if (num4 > 1)
  2416.                     {
  2417.                         bigIntegerBuilder.EnsureWritable(num4, 0);
  2418.                     }
  2419.                     BigIntegerBuilder bigIntegerBuilder1 = new BigIntegerBuilder(num4);
  2420.                     BigIntegerBuilder bigIntegerBuilder2 = new BigIntegerBuilder(num4);
  2421.                     bigIntegerBuilder2.Set(1);
  2422.                     if ((exponent & 1) == 0)
  2423.                     {
  2424.                         num = 1;
  2425.                     }
  2426.                     int num9 = exponent;
  2427.                     while (true)
  2428.                     {
  2429.                         if ((num9 & 1) != 0)
  2430.                         {
  2431.                             NumericsHelpers.<BigIntegerBuilder>(ref bigIntegerBuilder2, ref bigIntegerBuilder1);
  2432.                             bigIntegerBuilder2.Mul(ref bigIntegerBuilder, ref bigIntegerBuilder1);
  2433.                         }
  2434.                         int num10 = num9 >> 1;
  2435.                         num9 = num10;
  2436.                         if (num10 == 0)
  2437.                         {
  2438.                             break;
  2439.                         }
  2440.                         NumericsHelpers.<BigIntegerBuilder>(ref bigIntegerBuilder, ref bigIntegerBuilder1);
  2441.                         bigIntegerBuilder.Mul(ref bigIntegerBuilder1, ref bigIntegerBuilder1);
  2442.                     }
  2443.                     return bigIntegerBuilder2.GetInteger(num);
  2444.                 }
  2445.                 else
  2446.                 {
  2447.                     return value;
  2448.                 }
  2449.             }
  2450.             else
  2451.             {
  2452.                 return BigInteger.One;
  2453.             }
  2454.         }
  2455.         else
  2456.         {
  2457.             throw new ArgumentOutOfRangeException("exponent", SR.GetString("ArgumentOutOfRange_MustBeNonNeg"));
  2458.         }
  2459.     }
  2460.  
  2461.     [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
  2462.     public static BigInteger Remainder(BigInteger dividend, BigInteger divisor)
  2463.     {
  2464.         return dividend % divisor;
  2465.     }
  2466.  
  2467.     private void SetBitsFromDouble(double value)
  2468.     {
  2469.         int num = 0;
  2470.         int num1 = 0;
  2471.         ulong num2 = 0L;
  2472.         bool flag;
  2473.         NumericsHelpers.GetDoubleParts(value, out num, out num1, out num2, out flag);
  2474.         if (num2 != (long)0)
  2475.         {
  2476.             if (num1 > 0)
  2477.             {
  2478.                 if (num1 > 11)
  2479.                 {
  2480.                     num2 = num2 << 11;
  2481.                     num1 = num1 - 11;
  2482.                     int num3 = (num1 - 1) / 32 + 1;
  2483.                     int num4 = num3 * 32 - num1;
  2484.                     this._bits = new uint[num3 + 2];
  2485.                     this._bits[num3 + 1] = (uint)(num2 >> (num4 + 32 & 63));
  2486.                     this._bits[num3] = (uint)(num2 >> (num4 & 63));
  2487.                     if (num4 > 0)
  2488.                     {
  2489.                         this._bits[num3 - 1] = (uint)num2 << (32 - num4 & 31);
  2490.                     }
  2491.                     this._sign = num;
  2492.                 }
  2493.                 else
  2494.                 {
  2495.                     *(this) = num2 << (num1 & 63);
  2496.                     if (num < 0)
  2497.                     {
  2498.                         this._sign = -this._sign;
  2499.                         return;
  2500.                     }
  2501.                 }
  2502.             }
  2503.             else
  2504.             {
  2505.                 if (num1 > -64)
  2506.                 {
  2507.                     *(this) = num2 >> (-num1 & 63);
  2508.                     if (num < 0)
  2509.                     {
  2510.                         this._sign = -this._sign;
  2511.                         return;
  2512.                     }
  2513.                 }
  2514.                 else
  2515.                 {
  2516.                     *(this) = BigInteger.Zero;
  2517.                     return;
  2518.                 }
  2519.             }
  2520.             return;
  2521.         }
  2522.         else
  2523.         {
  2524.             *(this) = BigInteger.Zero;
  2525.             return;
  2526.         }
  2527.     }
  2528.  
  2529.     [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
  2530.     public static BigInteger Subtract(BigInteger left, BigInteger right)
  2531.     {
  2532.         return left - right;
  2533.     }
  2534.  
  2535.     public byte[] ToByteArray()
  2536.     {
  2537.         uint[] numArray;
  2538.         byte num;
  2539.         int num1;
  2540.         byte num2;
  2541.         if (this._bits != null || this._sign != 0)
  2542.         {
  2543.             if (this._bits != null)
  2544.             {
  2545.                 if (this._sign != -1)
  2546.                 {
  2547.                     numArray = this._bits;
  2548.                     num = 0;
  2549.                 }
  2550.                 else
  2551.                 {
  2552.                     numArray = (uint[])this._bits.Clone();
  2553.                     NumericsHelpers.DangerousMakeTwosComplement(numArray);
  2554.                     num = 255;
  2555.                 }
  2556.             }
  2557.             else
  2558.             {
  2559.                 uint[] numArray1 = new uint[1];
  2560.                 numArray1[0] = this._sign;
  2561.                 numArray = numArray1;
  2562.                 if (this._sign < 0)
  2563.                 {
  2564.                     num2 = 255;
  2565.                 }
  2566.                 else
  2567.                 {
  2568.                     num2 = 0;
  2569.                 }
  2570.                 num = (byte)num2;
  2571.             }
  2572.             byte[] numArray2 = new byte[4 * (int)numArray.Length];
  2573.             int num3 = 0;
  2574.             for (int i = 0; i < (int)numArray.Length; i++)
  2575.             {
  2576.                 uint num4 = numArray[i];
  2577.                 for (int j = 0; j < 4; j++)
  2578.                 {
  2579.                     int num5 = num3;
  2580.                     num3 = num5 + 1;
  2581.                     numArray2[num5] = (byte)(num4 & 255);
  2582.                     num4 = num4 >> 8;
  2583.                 }
  2584.             }
  2585.             int length = (int)numArray2.Length - 1;
  2586.             while (length > 0 && numArray2[length] == num)
  2587.             {
  2588.                 length--;
  2589.             }
  2590.             bool flag = (numArray2[length] & 128) != (num & 128);
  2591.             int num6 = length + 1;
  2592.             if (flag)
  2593.             {
  2594.                 num1 = 1;
  2595.             }
  2596.             else
  2597.             {
  2598.                 num1 = 0;
  2599.             }
  2600.             byte[] numArray3 = new byte[num6 + num1];
  2601.             Array.Copy(numArray2, numArray3, length + 1);
  2602.             if (flag)
  2603.             {
  2604.                 numArray3[(int)numArray3.Length - 1] = num;
  2605.             }
  2606.             return numArray3;
  2607.         }
  2608.         else
  2609.         {
  2610.             byte[] numArray4 = new byte[1];
  2611.             return numArray4;
  2612.         }
  2613.     }
  2614.  
  2615.     public override string ToString()
  2616.     {
  2617.         return BigNumber.FormatBigInteger(this, null, NumberFormatInfo.CurrentInfo);
  2618.     }
  2619.  
  2620.     public string ToString(IFormatProvider provider)
  2621.     {
  2622.         return BigNumber.FormatBigInteger(this, null, NumberFormatInfo.GetInstance(provider));
  2623.     }
  2624.  
  2625.     public string ToString(string format)
  2626.     {
  2627.         return BigNumber.FormatBigInteger(this, format, NumberFormatInfo.CurrentInfo);
  2628.     }
  2629.  
  2630.     public string ToString(string format, IFormatProvider provider)
  2631.     {
  2632.         return BigNumber.FormatBigInteger(this, format, NumberFormatInfo.GetInstance(provider));
  2633.     }
  2634.  
  2635.     private uint[] ToUInt32Array()
  2636.     {
  2637.         uint[] numArray;
  2638.         uint num;
  2639.         int num1;
  2640.         byte num2;
  2641.         if (this._bits != null || this._sign != 0)
  2642.         {
  2643.             if (this._bits != null)
  2644.             {
  2645.                 if (this._sign != -1)
  2646.                 {
  2647.                     numArray = this._bits;
  2648.                     num = 0;
  2649.                 }
  2650.                 else
  2651.                 {
  2652.                     numArray = (uint[])this._bits.Clone();
  2653.                     NumericsHelpers.DangerousMakeTwosComplement(numArray);
  2654.                     num = -1;
  2655.                 }
  2656.             }
  2657.             else
  2658.             {
  2659.                 uint[] numArray1 = new uint[1];
  2660.                 numArray1[0] = this._sign;
  2661.                 numArray = numArray1;
  2662.                 if (this._sign < 0)
  2663.                 {
  2664.                     num2 = -1;
  2665.                 }
  2666.                 else
  2667.                 {
  2668.                     num2 = 0;
  2669.                 }
  2670.                 num = (uint)num2;
  2671.             }
  2672.             int length = (int)numArray.Length - 1;
  2673.             while (length > 0 && numArray[length] == num)
  2674.             {
  2675.                 length--;
  2676.             }
  2677.             bool flag = (numArray[length] & -2147483648) != (num & -2147483648);
  2678.             int num3 = length + 1;
  2679.             if (flag)
  2680.             {
  2681.                 num1 = 1;
  2682.             }
  2683.             else
  2684.             {
  2685.                 num1 = 0;
  2686.             }
  2687.             uint[] numArray2 = new uint[num3 + num1];
  2688.             Array.Copy(numArray, numArray2, length + 1);
  2689.             if (flag)
  2690.             {
  2691.                 numArray2[(int)numArray2.Length - 1] = num;
  2692.             }
  2693.             return numArray2;
  2694.         }
  2695.         else
  2696.         {
  2697.             uint[] numArray3 = new uint[1];
  2698.             return numArray3;
  2699.         }
  2700.     }
  2701.  
  2702.     public static bool TryParse(string value, out BigInteger result)
  2703.     {
  2704.         return BigNumber.TryParseBigInteger(value, NumberStyles.Integer, NumberFormatInfo.CurrentInfo, out result);
  2705.     }
  2706.  
  2707.     public static bool TryParse(string value, NumberStyles style, IFormatProvider provider, out BigInteger result)
  2708.     {
  2709.         return BigNumber.TryParseBigInteger(value, style, NumberFormatInfo.GetInstance(provider), out result);
  2710.     }
  2711. }
  2712.  
  2713.  Expand All Members
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement