public static Rational simplify(final Rational r) { BigInteger n = OWLRealUtils.bigInteger(r.getNumerator()); BigInteger d = OWLRealUtils.bigInteger(r.getDenominator()); BigInteger gcd = n.gcd(d); while (!gcd.equals(BigInteger.ONE)) { n = n.divide(gcd); d = d.divide(gcd); gcd = n.gcd(d); } final Number canonicalNum = OWLRealUtils.getCanonicalObject(n); final Number canonicalDenom = OWLRealUtils.getCanonicalObject(d); if (canonicalNum.equals(r.getNumerator()) && canonicalDenom.equals(r.getDenominator())) return r; else return new Rational(canonicalNum, canonicalDenom); }
public static Rational simplify(final Rational r) { BigInteger n = OWLRealUtils.bigInteger(r.getNumerator()); BigInteger d = OWLRealUtils.bigInteger(r.getDenominator()); BigInteger gcd = n.gcd(d); while (!gcd.equals(BigInteger.ONE)) { n = n.divide(gcd); d = d.divide(gcd); gcd = n.gcd(d); } final Number canonicalNum = OWLRealUtils.getCanonicalObject(n); final Number canonicalDenom = OWLRealUtils.getCanonicalObject(d); if (canonicalNum.equals(r.getNumerator()) && canonicalDenom.equals(r.getDenominator())) return r; else return new Rational(canonicalNum, canonicalDenom); }
throw new IllegalArgumentException(); return bigInteger(r.getNumerator()); default: throw new IllegalArgumentException();
throw new IllegalArgumentException(); return bigInteger(r.getNumerator()); default: throw new IllegalArgumentException();
return OWLRealUtils.compare(a.getNumerator(), b.getNumerator()); else final BigInteger aprod = OWLRealUtils.bigInteger(a.getNumerator()).multiply(OWLRealUtils.bigInteger(b.getDenominator())); final BigInteger bprod = OWLRealUtils.bigInteger(b.getNumerator()).multiply(OWLRealUtils.bigInteger(a.getDenominator())); return aprod.compareTo(bprod);
return OWLRealUtils.compare(a.getNumerator(), b.getNumerator()); else final BigInteger aprod = OWLRealUtils.bigInteger(a.getNumerator()).multiply(OWLRealUtils.bigInteger(b.getDenominator())); final BigInteger bprod = OWLRealUtils.bigInteger(b.getNumerator()).multiply(OWLRealUtils.bigInteger(a.getDenominator())); return aprod.compareTo(bprod);