/** * Returns a property for a tag with a RATIONAL value. If rawOutput is true, returns a property * with type RATIONAL. Otherwise, returns a property with type STRING, and the text representation * of the Rational value as a floating-point ratio. */ protected Property addRationalProperty(String name, Rational r, boolean rawOutput) { Property prop = null; if (!rawOutput) { prop = new Property(name, PropertyType.STRING, _format.format(r.toDouble())); } if (prop == null) { prop = new Property(name, PropertyType.RATIONAL, r); } return prop; }
protected static Rational average(Rational r1, Rational r2) { long d1 = r1.getDenominator(); long d2 = r2.getDenominator(); Rational f1 = new Rational(r1.getNumerator() * d2, r1.getDenominator() * d2); Rational f2 = new Rational(r2.getNumerator() * d1, r2.getDenominator() * d1); return new Rational((f1.getNumerator() + f2.getNumerator()) / 2, f1.getDenominator()); }