BigFraction extends Number implements FieldElement<BigFraction>, Comparable<BigFraction>, Serializable { public BigFraction subtract(final BigInteger bg) { if (bg == null) { throw new NullArgumentException(); } return new BigFraction(numerator.subtract(denominator.multiply(bg)), denominator); } BigFraction(final BigInteger num);  BigFraction(BigInteger num, BigInteger den);  BigFraction(final double value);  BigFraction(final double value, final double epsilon,
                       final int maxIterations); private  BigFraction(final double value, final double epsilon,
                        final int maxDenominator, int maxIterations);  BigFraction(final double value, final int maxDenominator);  BigFraction(final int num);  BigFraction(final int num, final int den);  BigFraction(final long num);  BigFraction(final long num, final long den); static BigFraction getReducedFraction(final int numerator,
                                                 final int denominator); BigFraction abs(); BigFraction add(final BigInteger bg); BigFraction add(final int i); BigFraction add(final long l); BigFraction add(final BigFraction fraction); BigDecimal bigDecimalValue(); BigDecimal bigDecimalValue(final int roundingMode); BigDecimal bigDecimalValue(final int scale, final int roundingMode); int compareTo(final BigFraction object); BigFraction divide(final BigInteger bg); BigFraction divide(final int i); BigFraction divide(final long l); BigFraction divide(final BigFraction fraction); @Override double doubleValue(); @Override boolean equals(final Object other); @Override float floatValue(); BigInteger getDenominator(); int getDenominatorAsInt(); long getDenominatorAsLong(); BigInteger getNumerator(); int getNumeratorAsInt(); long getNumeratorAsLong(); @Override int hashCode(); @Override int intValue(); @Override long longValue(); BigFraction multiply(final BigInteger bg); BigFraction multiply(final int i); BigFraction multiply(final long l); BigFraction multiply(final BigFraction fraction); BigFraction negate(); double percentageValue(); BigFraction pow(final int exponent); BigFraction pow(final long exponent); BigFraction pow(final BigInteger exponent); double pow(final double exponent); BigFraction reciprocal(); BigFraction reduce(); BigFraction subtract(final BigInteger bg); BigFraction subtract(final int i); BigFraction subtract(final long l); BigFraction subtract(final BigFraction fraction); @Override String toString(); BigFractionField getField(); static final BigFraction TWO; static final BigFraction ONE; static final BigFraction ZERO; static final BigFraction MINUS_ONE; static final BigFraction FOUR_FIFTHS; static final BigFraction ONE_FIFTH; static final BigFraction ONE_HALF; static final BigFraction ONE_QUARTER; static final BigFraction ONE_THIRD; static final BigFraction THREE_FIFTHS; static final BigFraction THREE_QUARTERS; static final BigFraction TWO_FIFTHS; static final BigFraction TWO_QUARTERS; static final BigFraction TWO_THIRDS; }
@Test public void testSubtract() { BigFraction a = new BigFraction(1, 2); BigFraction b = new BigFraction(2, 3); assertFraction(0, 1, a.subtract(a)); assertFraction(-1, 6, a.subtract(b)); assertFraction(1, 6, b.subtract(a)); assertFraction(0, 1, b.subtract(b)); BigFraction f = new BigFraction(1, 1); try { f.subtract((BigFraction) null); Assert.fail("expecting NullArgumentException"); } catch (NullArgumentException ex) { } BigFraction f1 = new BigFraction(1, 32768 * 3); BigFraction f2 = new BigFraction(1, 59049); f = f1.subtract(f2); Assert.assertEquals(-13085, f.getNumeratorAsInt()); Assert.assertEquals(1934917632, f.getDenominatorAsInt()); f1 = new BigFraction(Integer.MIN_VALUE, 3); f2 = new BigFraction(1, 3).negate(); f = f1.subtract(f2); Assert.assertEquals(Integer.MIN_VALUE + 1, f.getNumeratorAsInt()); Assert.assertEquals(3, f.getDenominatorAsInt()); f1 = new BigFraction(Integer.MAX_VALUE, 1); f2 = BigFraction.ONE; f = f1.subtract(f2); Assert.assertEquals(Integer.MAX_VALUE - 1, f.getNumeratorAsInt()); Assert.assertEquals(1, f.getDenominatorAsInt()); }