1 8 package org.lsmp.djep.groupJep.groups; 9 import java.math.*; 10 11 import org.lsmp.djep.groupJep.interfaces.*; 12 import org.lsmp.djep.groupJep.values.*; 13 14 20 public class Rationals extends Group implements FieldI,OrderedSetI,HasPowerI { 21 22 private Rational ZERO = new Rational(BigInteger.valueOf(0)); 23 private Rational ONE = new Rational(BigInteger.valueOf(1)); 24 25 public Rationals() {} 26 27 public Number getZERO() { 28 return ZERO; 29 } 30 31 public Number getONE() { 32 return ONE; 33 } 34 35 public Number getInverse(Number num) { 36 return ((Rational) num).negate(); 37 } 38 39 public Number getMulInverse(Number num) { 40 return ((Rational) num).inverse(); 41 } 42 43 public Number add(Number a, Number b) { 44 return ((Rational) a).add((Rational) b); 45 } 46 47 public Number sub(Number a, Number b) { 48 return ((Rational) a).sub((Rational) b); 49 } 50 51 public Number mul(Number a, Number b) { 52 return ((Rational) a).mul((Rational) b); 53 } 54 55 public Number div(Number a, Number b) { 56 return ((Rational) a).div((Rational) b); 57 } 58 59 public Number pow(Number a, Number b) { 60 return ((Rational) a).pow((Rational) b); 61 } 62 63 public boolean equals(Number a,Number b) 64 { 65 return ((Rational) a).compareTo((Rational) b) == 0; 66 } 67 68 public int compare(Number a,Number b) 69 { 70 return ((Rational) a).compareTo((Rational) b); 71 } 72 73 public Number valueOf(String s) { 74 return Rational.valueOf(s); 75 } 76 77 public String toString() { return "Q"; } 78 } 79 | Popular Tags |