Fraction extends Number implements FieldElement<Fraction>, Comparable<Fraction>, Serializable { public Fraction negate() { if (numerator==Integer.MIN_VALUE) { throw new MathArithmeticException(LocalizedFormats.OVERFLOW_IN_FRACTION, numerator, denominator); } return new Fraction(-numerator, denominator); } Fraction(double value);  Fraction(double value, double epsilon, int maxIterations);  Fraction(double value, int maxDenominator); private  Fraction(double value, double epsilon, int maxDenominator, int maxIterations);  Fraction(int num);  Fraction(int num, int den); Fraction abs(); int compareTo(Fraction object); @Override double doubleValue(); @Override boolean equals(Object other); @Override float floatValue(); int getDenominator(); int getNumerator(); @Override int hashCode(); @Override int intValue(); @Override long longValue(); Fraction negate(); Fraction reciprocal(); Fraction add(Fraction fraction); Fraction add(final int i); Fraction subtract(Fraction fraction); Fraction subtract(final int i); Fraction multiply(Fraction fraction); Fraction multiply(final int i); Fraction divide(Fraction fraction); Fraction divide(final int i); double percentageValue(); static Fraction getReducedFraction(int numerator, int denominator); @Override String toString(); FractionField getField(); static final Fraction TWO; static final Fraction ONE; static final Fraction ZERO; static final Fraction FOUR_FIFTHS; static final Fraction ONE_FIFTH; static final Fraction ONE_HALF; static final Fraction ONE_QUARTER; static final Fraction ONE_THIRD; static final Fraction THREE_FIFTHS; static final Fraction THREE_QUARTERS; static final Fraction TWO_FIFTHS; static final Fraction TWO_QUARTERS; static final Fraction TWO_THIRDS; static final Fraction MINUS_ONE; }
@Test public void testNegate() { Fraction f = null; f = new Fraction(50, 75); f = f.negate(); Assert.assertEquals(-2, f.getNumerator()); Assert.assertEquals(3, f.getDenominator()); f = new Fraction(-50, 75); f = f.negate(); Assert.assertEquals(2, f.getNumerator()); Assert.assertEquals(3, f.getDenominator()); f = new Fraction(Integer.MAX_VALUE-1, Integer.MAX_VALUE); f = f.negate(); Assert.assertEquals(Integer.MIN_VALUE+2, f.getNumerator()); Assert.assertEquals(Integer.MAX_VALUE, f.getDenominator()); f = new Fraction(Integer.MIN_VALUE, 1); try { f = f.negate(); Assert.fail("expecting MathArithmeticException"); } catch (MathArithmeticException ex) {} }