// TODO: put this somewhere else... public static void printRow( String name, Rational value, ColumnTextWriter colpp, boolean excludeZero) { if (!value.isZero() || !excludeZero) { colpp.writeCol(name); colpp.writeCol(value.toString()); if (!BigIntegerUtils.one(value.den)) { colpp.writeCol(String.format("%.3f", value.doubleValue())); } colpp.endRow(); } }
public int compareTo(Rational other) { if (num.equals(other.num) && den.equals(other.den)) return 0; // see if it is a num only compare... if (den.equals(other.den)) return (greater(other.num, this.num)) ? -1 : 1; // check signs... if ((zero(num) || negative(num)) && positive(other.num)) return -1; else if (positive(num) && (zero(other.num) || negative(other.num))) return 1; BigInteger c1 = new BigInteger(other.num.toString()); BigInteger c2 = new BigInteger(other.den.toString()); Rational c = new Rational(c1, c2); c = c.negate(); c.addEq(this); return (c.isZero() ? 0 : (negative(c.num) ? -1 : 1)); }