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

Add() public méthode

public Add ( BigIntegerBuilder &reg ) : void
reg BigIntegerBuilder
Résultat void
        public void Add(ref BigIntegerBuilder reg) {
            if (reg._iuLast == 0) {
                this.Add(reg._uSmall);
            }
            else if (this._iuLast == 0) {
                uint u = this._uSmall;
                if (u == 0) {
                    this = new BigIntegerBuilder(ref reg);
                }
                else {
                    this.Load(ref reg, 1);
                    this.Add(u);
                }
            }
            else {
                this.EnsureWritable(Math.Max(this._iuLast, reg._iuLast) + 1, 1);
                int iu = reg._iuLast + 1;
                if (this._iuLast < reg._iuLast) {
                    iu = this._iuLast + 1;
                    Array.Copy(reg._rgu, (int)(this._iuLast + 1), this._rgu, (int)(this._iuLast + 1), (int)(reg._iuLast - this._iuLast));
                    this._iuLast = reg._iuLast;
                }
                uint uCarry = 0;
                for (int i = 0; i < iu; i++) {
                    uCarry = AddCarry(ref this._rgu[i], reg._rgu[i], uCarry);
                }
                if (uCarry != 0) {
                    this.ApplyCarry(iu);
                }
            }
        }

Same methods

BigIntegerBuilder::Add ( uint u ) : void

Usage Example

        /// <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::Add