Exemplo n.º 1
0
 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;
 }
Exemplo n.º 2
0
 public fraction divide(fraction x) {
   fraction t = new fraction(x.den.multiply(num), x.num.multiply(den));
   t.fix();
   return t;
 }
Exemplo n.º 3
0
 public fraction subtract(fraction x) {
   return this.add(x.negate());
 }