/// <include file='../../docs.xml' /// path='docs/doc[@name="M:PeterO.Numbers.FastInteger.Negate"]/*'/> internal FastInteger Negate() { this.CheckFrozen(); switch (this.integerMode) { case 0: if (this.smallValue == Int32.MinValue) { // would overflow, convert to large this.integerMode = 1; this.mnum = MutableNumber.FromEInteger(ValueNegativeInt32MinValue); } else { smallValue = -smallValue; } break; case 1: this.integerMode = 2; this.largeValue = this.mnum.ToEInteger(); this.largeValue = -(EInteger)this.largeValue; break; case 2: this.largeValue = -(EInteger)this.largeValue; break; default: throw new InvalidOperationException(); } return(this); }
internal FastInteger Divide(int divisor) { this.CheckFrozen(); if (divisor != 0) { switch (this.integerMode) { case 0: if (divisor == -1 && this.smallValue == Int32.MinValue) { // would overflow, convert to large this.integerMode = 1; this.mnum = MutableNumber.FromEInteger(ValueNegativeInt32MinValue); } else { smallValue /= divisor; } break; case 1: this.integerMode = 2; this.largeValue = this.mnum.ToEInteger(); this.largeValue /= (EInteger)divisor; if (this.largeValue.IsZero) { this.integerMode = 0; this.smallValue = 0; } break; case 2: this.largeValue /= (EInteger)divisor; if (this.largeValue.IsZero) { this.integerMode = 0; this.smallValue = 0; } break; default: throw new InvalidOperationException(); } } else { throw new DivideByZeroException(); } return(this); }
internal FastInteger Increment() { this.CheckFrozen(); if (this.integerMode == 0) { if (this.smallValue != Int32.MaxValue) { ++this.smallValue; } else { this.integerMode = 1; this.mnum = MutableNumber.FromEInteger(ValueNegativeInt32MinValue); } return(this); } return(this.AddInt(1)); }
internal FastInteger Decrement() { this.CheckFrozen(); if (this.integerMode == 0) { if (this.smallValue != Int32.MinValue) { --this.smallValue; } else { this.integerMode = 1; this.mnum = MutableNumber.FromEInteger(ValueInt32MinValue); this.mnum.SubtractInt(1); } return(this); } return(this.SubtractInt(1)); }
internal static FastInteger FromBig(EInteger bigintVal) { if (bigintVal.CanFitInInt32()) { return(new FastInteger(bigintVal.ToInt32Unchecked())); } if (bigintVal.Sign > 0) { var fi = new FastInteger(0); fi.integerMode = 1; fi.mnum = MutableNumber.FromEInteger(bigintVal); return(fi); } else { var fi = new FastInteger(0); fi.integerMode = 2; fi.largeValue = bigintVal; return(fi); } }
internal static int[] GetLastWords(EInteger bigint, int numWords32Bit) { return (MutableNumber.FromEInteger(bigint).GetLastWordsInternal(numWords32Bit)); }