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); }
protected override Number Subtract(Number n) { var longNumber = n.ConvertCast<LongIntegerNumber>(); return Add(new LongIntegerNumber(longNumber.parts, !longNumber.isNegative)); }
protected override Number Power(Number n) { var b = n.ConvertCast<LongIntegerNumber>(); return FastPower(this, b); }
protected override Number Multiply(Number n) { var longNumber = n.ConvertCast<LongIntegerNumber>(); return new LongIntegerNumber(MultiplyCore(this.parts, longNumber.parts), isNegative ^ longNumber.isNegative); }
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); }
internal LongIntegerNumber Modulo(Number n) { var longNumber = n.ConvertCast<LongIntegerNumber>(); LongIntegerNumber remain = Zero; DivieImpl(parts, longNumber.parts, out remain); return remain; }