@Test public void testFloor() { final int[] numerators = { 0, 1, 2, 3, 9, 10, 11, 12}; final int[] denominators = { 3, 3, 3, 3, 3, 3, 3, 3}; final int[] positives = { 0, 0, 0, 1, 3, 3, 3, 4}; final int[] negatives = {-0, -1, -1, -1, -3, -4, -4, -4}; for (int i=0; i<numerators.length; i++) { for (int s=0; s<4; s++) { int numerator = numerators [i]; int denominator = denominators[i]; if ((s & 1) != 0) numerator = -numerator; if ((s & 2) != 0) denominator = -denominator; final int[] expected = (numerator * denominator >= 0) ? positives : negatives; final String label = "floor(" + numerator + '/' + denominator + ')'; assertEquals(label, expected[i], Fraction.floor(numerator, denominator)); } } }
public static int floor(final int numerator, final int denominator) { int n = numerator / denominator; if ((numerator ^ denominator) < 0 && (numerator % denominator) != 0) { n--; } return n; }
Fraction extends Number implements Comparable<Fraction>, Cloneable { public static int floor(final int numerator, final int denominator) { int n = numerator / denominator; if ((numerator ^ denominator) < 0 && (numerator % denominator) != 0) { n--; } return n; } }
Fraction extends Number implements Comparable<Fraction>, Cloneable { public static int floor(final int numerator, final int denominator) { int n = numerator / denominator; if ((numerator ^ denominator) < 0 && (numerator % denominator) != 0) { n--; } return n; } Fraction();  Fraction(final Fraction other);  Fraction(final int numerator);  Fraction(final int numerator, final int denominator); }
Fraction extends Number implements Comparable<Fraction>, Cloneable { public static int floor(final int numerator, final int denominator) { int n = numerator / denominator; if ((numerator ^ denominator) < 0 && (numerator % denominator) != 0) { n--; } return n; } Fraction();  Fraction(final Fraction other);  Fraction(final int numerator);  Fraction(final int numerator, final int denominator); void set(final int numerator, final int denominator); void add(final Fraction other); void subtract(final Fraction other); void multiply(final Fraction other); void divide(final Fraction other); int numerator(); int denominator(); @Override double doubleValue(); @Override float floatValue(); @Override long longValue(); @Override int intValue(); static long round(final long numerator, final long denominator); static int round(final int numerator, final int denominator); static int floor(final int numerator, final int denominator); static int ceil(final int numerator, final int denominator); int compareTo(final Fraction other); @Override boolean equals(final Object other); @Override Fraction clone(); @Override String toString(); }
Fraction extends Number implements Comparable<Fraction>, Cloneable { public static int floor(final int numerator, final int denominator) { int n = numerator / denominator; if ((numerator ^ denominator) < 0 && (numerator % denominator) != 0) { n--; } return n; } Fraction();  Fraction(final Fraction other);  Fraction(final int numerator);  Fraction(final int numerator, final int denominator); void set(final int numerator, final int denominator); void add(final Fraction other); void subtract(final Fraction other); void multiply(final Fraction other); void divide(final Fraction other); int numerator(); int denominator(); @Override double doubleValue(); @Override float floatValue(); @Override long longValue(); @Override int intValue(); static long round(final long numerator, final long denominator); static int round(final int numerator, final int denominator); static int floor(final int numerator, final int denominator); static int ceil(final int numerator, final int denominator); int compareTo(final Fraction other); @Override boolean equals(final Object other); @Override Fraction clone(); @Override String toString();  }