public fraction add(fraction x) { BigInteger gcd = den.gcd(x.den); BigInteger A = x.den.divide(gcd); BigInteger B = den.divide(gcd); BigInteger newNum = num.multiply(A).add(x.num.multiply(B)); BigInteger newDen = den.multiply(A); fraction t = new fraction(newNum, newDen); t.fix(); return t; }
public fraction divide(fraction x) { fraction t = new fraction(x.den.multiply(num), x.num.multiply(den)); t.fix(); return t; }
public fraction subtract(fraction x) { return this.add(x.negate()); }