System.Numerics.BigIntegerBuilder.SetSizeKeep C# (CSharp) Méthode

SetSizeKeep() private méthode

private SetSizeKeep ( int cu, int cuExtra ) : void
cu int
cuExtra int
Résultat void
        private void SetSizeKeep(int cu, int cuExtra) {
            if (cu <= 1) {
                if (this._iuLast > 0) {
                    this._uSmall = this._rgu[0];
                }
                this._iuLast = 0;
            }
            else {
                if (!this._fWritable || (this._rgu.Length < cu)) {
                    uint[] destinationArray = new uint[cu + cuExtra];
                    if (this._iuLast == 0) {
                        destinationArray[0] = this._uSmall;
                    }
                    else {
                        Array.Copy(this._rgu, 0, destinationArray, 0, Math.Min(cu, this._iuLast + 1));
                    }
                    this._rgu = destinationArray;
                    this._fWritable = true;
                }
                else if ((this._iuLast + 1) < cu) {
                    Array.Clear(this._rgu, this._iuLast + 1, (cu - this._iuLast) - 1);
                    if (this._iuLast == 0) {
                        this._rgu[0] = this._uSmall;
                    }
                }
                this._iuLast = cu - 1;
            }
        }

Usage Example

Exemple #1
0
        private static void LehmerGcd(ref BigIntegerBuilder reg1, ref BigIntegerBuilder reg2)
        {
            int  num2;
            uint num11;
            int  sign = 1;

Label_0002:
            num2 = reg1._iuLast + 1;
            int b = reg2._iuLast + 1;

            if (num2 < b)
            {
#if !(dotNET10 || dotNET11 || dotNETCF10)
                NumericsHelpers.Swap <BigIntegerBuilder>(ref reg1, ref reg2);
                NumericsHelpers.Swap <int>(ref num2, ref b);
#else
                NumericsHelpers.Swap(ref reg1, ref reg2);
                NumericsHelpers.Swap(ref num2, ref b);
#endif
            }
            if (b == 1)
            {
                if (num2 == 1)
                {
                    reg1._uSmall = NumericsHelpers.GCD(reg1._uSmall, reg2._uSmall);
                    return;
                }
                if (reg2._uSmall != 0)
                {
                    reg1.Set(NumericsHelpers.GCD(Mod(ref reg1, reg2._uSmall), reg2._uSmall));
                }
                return;
            }
            if (num2 == 2)
            {
                reg1.Set(NumericsHelpers.GCD(reg1.GetHigh2(2), reg2.GetHigh2(2)));
                return;
            }
            if (b <= (num2 - 2))
            {
                reg1.Mod(ref reg2);
                goto Label_0002;
            }
            ulong a    = reg1.GetHigh2(num2);
            ulong num5 = reg2.GetHigh2(num2);
            int   num6 = NumericsHelpers.CbitHighZero((ulong)(a | num5));
            if (num6 > 0)
            {
                a    = (a << num6) | (reg1._rgu[num2 - 3] >> (0x20 - num6));
                num5 = (num5 << num6) | (reg2._rgu[num2 - 3] >> (0x20 - num6));
            }
            if (a < num5)
            {
#if !(dotNET10 || dotNET11 || dotNETCF10)
                NumericsHelpers.Swap <ulong>(ref a, ref num5);
                NumericsHelpers.Swap <BigIntegerBuilder>(ref reg1, ref reg2);
#else
                NumericsHelpers.Swap(ref a, ref num5);
                NumericsHelpers.Swap(ref reg1, ref reg2);
#endif
            }
            if ((a == ulong.MaxValue) || (num5 == ulong.MaxValue))
            {
                a    = a >> 1;
                num5 = num5 >> 1;
            }
            if (a == num5)
            {
                reg1.Sub(ref sign, ref reg2);
                goto Label_0002;
            }
            if (NumericsHelpers.GetHi(num5) == 0)
            {
                reg1.Mod(ref reg2);
                goto Label_0002;
            }
            uint num7  = 1;
            uint num8  = 0;
            uint num9  = 0;
            uint num10 = 1;
Label_0159:
            num11 = 1;
            ulong num12 = a - num5;
            while ((num12 >= num5) && (num11 < 0x20))
            {
                num12 -= num5;
                num11++;
            }
            if (num12 >= num5)
            {
                ulong num13 = a / num5;
                if (num13 > 0xffffffffL)
                {
                    goto Label_029E;
                }
                num11 = (uint)num13;
                num12 = a - (num11 * num5);
            }
            ulong num14 = (ulong)num7 + (ulong)num11 * (ulong)num9;
            ulong num15 = (ulong)num8 + (ulong)num11 * (ulong)num10;
            if (((num14 <= 0x7fffffffL) && (num15 <= 0x7fffffffL)) && ((num12 >= num15) && ((num12 + num14) <= (num5 - num9))))
            {
                num7 = (uint)num14;
                num8 = (uint)num15;
                a    = num12;
                if (a > num8)
                {
                    num11 = 1;
                    num12 = num5 - a;
                    while ((num12 >= a) && (num11 < 0x20))
                    {
                        num12 -= a;
                        num11++;
                    }
                    if (num12 >= a)
                    {
                        ulong num16 = num5 / a;
                        if (num16 > 0xffffffffL)
                        {
                            goto Label_029E;
                        }
                        num11 = (uint)num16;
                        num12 = num5 - (num11 * a);
                    }
                    num14 = (ulong)num10 + (ulong)num11 * (ulong)num8;
                    num15 = (ulong)num9 + (ulong)num11 * (ulong)num7;
                    if (((num14 <= 0x7fffffffL) && (num15 <= 0x7fffffffL)) && ((num12 >= num15) && ((num12 + num14) <= (a - num8))))
                    {
                        num10 = (uint)num14;
                        num9  = (uint)num15;
                        num5  = num12;
                        if (num5 > num9)
                        {
                            goto Label_0159;
                        }
                    }
                }
            }
Label_029E:
            if (num8 == 0)
            {
                if ((a / ((ulong)2L)) >= num5)
                {
                    reg1.Mod(ref reg2);
                }
                else
                {
                    reg1.Sub(ref sign, ref reg2);
                }
            }
            else
            {
                reg1.SetSizeKeep(b, 0);
                reg2.SetSizeKeep(b, 0);
                int num17 = 0;
                int num18 = 0;
                for (int i = 0; i < b; i++)
                {
                    uint num20 = reg1._rgu[i];
                    uint num21 = reg2._rgu[i];
                    long num22 = (long)num20 * (long)num7 - (long)num21 * (long)num8 + (long)num17;
                    long num23 = (long)num21 * (long)num10 - (long)num20 * (long)num9 + (long)num18;
                    num17        = (int)(num22 >> 0x20);
                    num18        = (int)(num23 >> 0x20);
                    reg1._rgu[i] = (uint)num22;
                    reg2._rgu[i] = (uint)num23;
                }
                reg1.Trim();
                reg2.Trim();
            }
            goto Label_0002;
        }
All Usage Examples Of System.Numerics.BigIntegerBuilder::SetSizeKeep