예제 #1
0
        /// <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);
        }
예제 #2
0
        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);
        }
예제 #3
0
 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));
 }
예제 #4
0
 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));
 }
예제 #5
0
 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);
     }
 }
예제 #6
0
 internal static int[] GetLastWords(EInteger bigint, int numWords32Bit)
 {
     return
         (MutableNumber.FromEInteger(bigint).GetLastWordsInternal(numWords32Bit));
 }