private static Rational scaleRatio(Rational ratio, int num, int den) {
   int common = gcd(num, den);
   num /= common;
   den /= common;
   return new Rational(
       (int) (ratio.getNumerator() * (double) num), // saturate to int
       (int) (ratio.getDenominator() * (double) den)); // saturate to int
 }
 static Range<Rational> parseRationalRange(Object o, Range<Rational> fallback) {
   try {
     String s = (String) o;
     int ix = s.indexOf('-');
     if (ix >= 0) {
       return Range.create(
           Rational.parseRational(s.substring(0, ix)),
           Rational.parseRational(s.substring(ix + 1)));
     }
     Rational value = Rational.parseRational(s);
     return Range.create(value, value);
   } catch (ClassCastException e) {
   } catch (NumberFormatException e) {
   } catch (NullPointerException e) {
     return fallback;
   } catch (IllegalArgumentException e) {
   }
   Log.w(TAG, "could not parse rational range '" + o + "'");
   return fallback;
 }