Example #1
0
 Number Divide(Number n, bool allowFraction)
 {
     var longNumber = n.ConvertCast<LongIntegerNumber>();
     bool isResultNegative = isNegative ^ longNumber.isNegative;
     if(allowFraction && CompareCore(parts, longNumber.parts) < 0)
         return FractionNumber.Create(new LongIntegerNumber(parts, isResultNegative), new LongIntegerNumber(longNumber.parts, false)); ;
     return DivieCore(parts, longNumber.parts, isResultNegative, allowFraction);
 }
Example #2
0
 protected override Number Subtract(Number n)
 {
     var longNumber = n.ConvertCast<LongIntegerNumber>();
     return Add(new LongIntegerNumber(longNumber.parts, !longNumber.isNegative));
 }
Example #3
0
 protected override Number Power(Number n)
 {
     var b = n.ConvertCast<LongIntegerNumber>();
     return FastPower(this, b);
 }
Example #4
0
 protected override Number Multiply(Number n)
 {
     var longNumber = n.ConvertCast<LongIntegerNumber>();
     return new LongIntegerNumber(MultiplyCore(this.parts, longNumber.parts), isNegative ^ longNumber.isNegative);
 }
Example #5
0
 protected override Number Add(Number n)
 {
     var longNumber = n.ConvertCast<LongIntegerNumber>();
     if(!isNegative && !longNumber.isNegative)
         return AddCore(longNumber);
     if(longNumber.isNegative) {
         var invertedRight = new LongIntegerNumber(longNumber.parts, false);
         if(this < invertedRight)
             return new LongIntegerNumber(invertedRight.Subtract(this).ConvertCast<LongIntegerNumber>().parts, true);
     } else {
         var invertedLeft = new LongIntegerNumber(this.parts, false);
         if(longNumber < invertedLeft)
             return new LongIntegerNumber(invertedLeft.Subtract(longNumber).ConvertCast<LongIntegerNumber>().parts, true);
     }
     return AddCore(longNumber);
 }
Example #6
0
 internal LongIntegerNumber Modulo(Number n)
 {
     var longNumber = n.ConvertCast<LongIntegerNumber>();
     LongIntegerNumber remain = Zero;
     DivieImpl(parts, longNumber.parts, out remain);
     return remain;
 }