/** * @param that * @return */ public boolean isLargerThan(final BigInteger that) { return toBigNumerator().compareTo(that) > 0; }
@Override public IExpr remainder(final IExpr that) { if (that instanceof IntegerSym) { return valueOf(toBigNumerator().remainder(((IntegerSym) that).toBigNumerator())); } if (that instanceof BigIntegerSym) { return valueOf(toBigNumerator().remainder(((BigIntegerSym) that).fBigIntValue)); } return this; }
@Override public IInteger shiftLeft(final int n) { if (n == 0) { return this; } if (n <= 31) { return valueOf(fIntValue << n); } return valueOf(toBigNumerator().shiftLeft(n)); }
@Override public IExpr remainder(final IExpr that) { if (that instanceof IntegerSym) { return valueOf(fBigIntValue.remainder(((IntegerSym) that).toBigNumerator())); } if (that instanceof BigIntegerSym) { return valueOf(fBigIntValue.remainder(((BigIntegerSym) that).fBigIntValue)); } return this; }
public IInteger remainder(final IInteger that) { return valueOf(toBigNumerator().remainder(that.toBigNumerator())); }
@Override public IInteger div(final IInteger that) { if (that instanceof IntegerSym) { return valueOf(fIntValue / ((IntegerSym) that).fIntValue); } return valueOf(toBigNumerator().divide(that.toBigNumerator())); }
@Override public IInteger modPow(final IInteger exp, final IInteger m) { if (m.isZero()) { throw new ArithmeticException("the argument " + m.toString() + " should be nonzero."); } return valueOf(toBigNumerator().modPow(exp.toBigNumerator(), m.toBigNumerator())); }
@Override public IInteger mod(final IInteger that) { if (that instanceof IntegerSym) { return valueOf(IntMath.mod(fIntValue, ((IntegerSym) that).fIntValue)); } return valueOf(toBigNumerator().mod(that.toBigNumerator())); }
@Override public boolean isLessThan(ISignedNumber obj) { if (obj instanceof IntegerSym) { return fIntValue < ((IntegerSym) obj).fIntValue; } if (obj instanceof BigIntegerSym) { return toBigNumerator().compareTo(((BigIntegerSym) obj).toBigNumerator()) < 0; } if (obj instanceof AbstractFractionSym) { return -((AbstractFractionSym) obj).compareTo(AbstractFractionSym.valueOf(fIntValue)) < 0; } return doubleValue() < obj.doubleValue(); }
@Override public boolean isGreaterThan(ISignedNumber obj) { if (obj instanceof IntegerSym) { return fIntValue > ((IntegerSym) obj).fIntValue; } if (obj instanceof BigIntegerSym) { return toBigNumerator().compareTo(((BigIntegerSym) obj).toBigNumerator()) > 0; } if (obj instanceof AbstractFractionSym) { return -((AbstractFractionSym) obj).compareTo(AbstractFractionSym.valueOf(fIntValue)) > 0; } return doubleValue() > obj.doubleValue(); }
/** {@inheritDoc} */ @Override public IInteger[] divideAndRemainder(final IInteger that) { final IInteger[] res = new IntegerSym[2]; BigInteger[] largeRes = toBigNumerator().divideAndRemainder(that.toBigNumerator()); res[0] = valueOf(largeRes[0]); res[1] = valueOf(largeRes[1]); return res; }
@Override public IRational add(IRational parm1) { if (parm1.isZero()) { return this; } if (parm1 instanceof AbstractFractionSym) { return ((AbstractFractionSym) parm1).add(this); } if (parm1 instanceof IntegerSym) { IntegerSym is = (IntegerSym) parm1; long newnum = (long) fIntValue + (long) is.fIntValue; return valueOf(newnum); } BigIntegerSym p1 = (BigIntegerSym) parm1; BigInteger newnum = toBigNumerator().add(p1.toBigNumerator()); return valueOf(newnum); }
return valueOf(toBigNumerator().modInverse(that.toBigNumerator()));
@Override public IRational subtract(IRational parm1) { if (parm1.isZero()) { return this; } if (parm1 instanceof AbstractFractionSym) { return ((AbstractFractionSym) parm1).negate().add(this); } if (parm1 instanceof IntegerSym) { IntegerSym is = (IntegerSym) parm1; long newnum = (long) fIntValue - (long) is.fIntValue; return valueOf(newnum); } BigIntegerSym p1 = (BigIntegerSym) parm1; BigInteger newnum = toBigNumerator().subtract(p1.toBigNumerator()); return valueOf(newnum); }
/** * Returns the greatest common divisor of this large integer and the one specified. * */ @Override public IInteger gcd(final IInteger that) { if (that instanceof IntegerSym) { try { return valueOf(ArithmeticUtils.gcd(fIntValue, ((IntegerSym) that).fIntValue)); } catch (RuntimeException ex) { // } } return valueOf(toBigNumerator().gcd(that.toBigNumerator())); }
@Override public IRational multiply(IRational parm1) { if (parm1.isZero()) { return F.C0; } if (parm1.isOne()) { return this; } if (parm1.isMinusOne()) { return this.negate(); } if (parm1 instanceof AbstractFractionSym) { return ((AbstractFractionSym) parm1).multiply(this); } if (parm1 instanceof IntegerSym) { IntegerSym is = (IntegerSym) parm1; long newnum = (long) fIntValue * (long) is.fIntValue; return valueOf(newnum); } BigIntegerSym p1 = (BigIntegerSym) parm1; BigInteger newnum = toBigNumerator().multiply(p1.toBigNumerator()); return valueOf(newnum); }