System.Numerics.BigIntegerBuilder.Sub C# (CSharp) Метод

Sub() публичный Метод

public Sub ( int &sign, BigIntegerBuilder &reg ) : void
sign int
reg BigIntegerBuilder
Результат void
        public void Sub(ref int sign, ref BigIntegerBuilder reg) {
            if (reg._iuLast == 0) {
                this.Sub(ref sign, reg._uSmall);
            }
            else if (this._iuLast == 0) {
                uint u = this._uSmall;
                if (u == 0) {
                    this = new BigIntegerBuilder(ref reg);
                }
                else {
                    this.Load(ref reg);
                    this.Sub(ref sign, u);
                }
                sign = -sign;
            }
            else if (this._iuLast < reg._iuLast) {
                this.SubRev(ref reg);
                sign = -sign;
            }
            else {
                int iuMin = reg._iuLast + 1;
                if (this._iuLast == reg._iuLast) {
                    this._iuLast = BigInteger.GetDiffLength(this._rgu, reg._rgu, this._iuLast + 1) - 1;
                    if (this._iuLast < 0) {
                        this._iuLast = 0;
                        this._uSmall = 0;
                        return;
                    }
                    uint num3 = this._rgu[this._iuLast];
                    uint num4 = reg._rgu[this._iuLast];
                    if (this._iuLast == 0) {
                        if (num3 < num4) {
                            this._uSmall = num4 - num3;
                            sign = -sign;
                            return;
                        }
                        this._uSmall = num3 - num4;
                        return;
                    }
                    if (num3 < num4) {
                        reg._iuLast = this._iuLast;
                        this.SubRev(ref reg);
                        reg._iuLast = iuMin - 1;
                        sign = -sign;
                        return;
                    }
                    iuMin = this._iuLast + 1;
                }
                this.EnsureWritable();
                uint uBorrow = 0;
                for (int i = 0; i < iuMin; i++) {
                    uBorrow = SubBorrow(ref this._rgu[i], reg._rgu[i], uBorrow);
                }
                if (uBorrow != 0) {
                    this.ApplyBorrow(iuMin);
                }
                this.Trim();
            }
        }

Same methods

BigIntegerBuilder::Sub ( int &sign, uint u ) : void

Usage Example

Пример #1
0
        /// <summary>Adds the values of two specified <see cref="BigInteger" /> objects.</summary>
        /// <returns>The sum of <paramref name="left" /> and <paramref name="right" />.</returns>
        /// <param name="left">The first value to add.</param>
        /// <param name="right">The second value to add.</param>
        public static BigInteger operator +(BigInteger left, BigInteger right)
        {
            if (right.IsZero)
            {
                return(left);
            }

            if (left.IsZero)
            {
                return(right);
            }

            var signLeft  = 1;
            var signRight = 1;
            var regLeft   = new BigIntegerBuilder(left, ref signLeft);
            var regRight  = new BigIntegerBuilder(right, ref signRight);

            if (signLeft != signRight)
            {
                regLeft.Sub(ref signLeft, ref regRight);
            }
            else
            {
                regLeft.Add(ref regRight);
            }

            return(regLeft.GetInteger(signLeft));
        }
All Usage Examples Of System.Numerics.BigIntegerBuilder::Sub