/** * Quotient multiplication. * * @param S Quotient. * @return this*S. */ public Quotient<C> multiply(Quotient<C> S) { if (S == null || S.isZERO()) { return S; } if (num.isZERO()) { return this; } if (S.isONE()) { return this; } if (this.isONE()) { return S; } C n = num.multiply(S.num); C d = den.multiply(S.den); return new Quotient<C>(ring, n, d, false); }
/** * Quotient subtraction. * * @param S Quotient. * @return this-S. */ public Quotient<C> subtract(Quotient<C> S) { if (S == null || S.isZERO()) { return this; } C n = num.multiply(S.den); n = n.subtract(den.multiply(S.num)); C d = den.multiply(S.den); return new Quotient<C>(ring, n, d, false); }
// JAVA6only: @Override public int compareTo(Quotient<C> b) { if (b == null || b.isZERO()) { return this.signum(); } C r = num.multiply(b.den); C s = den.multiply(b.num); C x = r.subtract(s); return x.signum(); }
/** * Quotient division. * * @param S Quotient. * @return this/S. */ public Quotient<C> divide(Quotient<C> S) { return multiply(S.inverse()); }