@Override public int compareAbsValueToOne() { long num = fNumerator; if (fNumerator < 0) { num *= (-1); } if (isOne(num, fDenominator)) { return 0; } return (num > fDenominator) ? 1 : -1; }
/** * Return a new rational representing <code>this * other</code>. * * @param other big integer to multiply. * @return Product of <code>this</code> and <code>other</code>. */ public IFraction mul(BigInteger other) { if (other.bitLength() <= 31) { int oint = other.intValue(); if (oint == 1) return this; if (oint == -1) return this.negate(); long newnum = (long) fNumerator * oint; return valueOf(newnum, fDenominator); } if (this.isOne()) { return valueOf(other, BigInteger.ONE); } if (this.isMinusOne()) { return valueOf(other.negate(), BigInteger.ONE); } return valueOf(toBigNumerator().multiply(other), toBigDenominator()); }
/** * Return a new rational representing <code>this * other</code>. * * @param other Rational to multiply. * @return Product of <code>this</code> and <code>other</code>. */ @Override public IFraction mul(IFraction other) { if (other.isOne()) { return this; } if (this.isOne()) { return other; } if (other.isMinusOne()) { return this.negate(); } if (this.isMinusOne()) { return other.negate(); } if (other instanceof BigFractionSym) { return other.mul(this); } FractionSym fs = (FractionSym) other; long newnum = (long) fNumerator * fs.fNumerator; long newdenom = (long) fDenominator * fs.fDenominator; return valueOf(newnum, newdenom); }