BigIntegerAlgebra
).MyFractionAlgebra
it is sufficient to implement methods a.add(b), a.mul(b), a.div(b) or a.inv(), a.pow(int)
and
constructors MyFractionAlgebra(int,int), MyFractionAlgebra(int), MyFractionAlgebra(double)
to cover all possible arithmetic operations including mixed operations with integer and double
(see the unit tests on the next page).a
) the algebra class must implement
the interface JxnCloneableAlgebra
to avoid an unintended
modification of the operand.
operator | maps to the method signatures: |
@A(...) | new A(...) calls a constructor of class A |
a[b] | a.get(b) |
a^b ≡ a**b | a.pow(b) A.pow(a,b) a.pow( new A(b) ) new B(a).pow(b) Note: operator ^ for pow differs from java |
−a | a.neg() a.negate() a.mulL(−1) new A(−1).mul(a) Note: −a^b ≡ −(a^b) but −a * b ≡ (−a) * b |
a * b ≡ a b | a.mul(b) A.mul(a,b) a.mul( new A(b) ) b.mulL(a) new B(a).mul(b) a.multiply(b) A.multiply(a,b) a.multiply( new A(b) ) new B(a).multiply(b) |
a / b | a.div(b) A.div(a,b) a.div( new A(b) ) new B(a).div(b) a.divide(b) A.divide(a,b) a.divide( new A(b) ) new B(a).divide(b) c = new A(b).inv() c = new A(b).reciprocal() c = b.inv() c = b.reciprocal() followed by a.mul(c) A.mul(a,c) a.mul( new A(c) ) c.mulL(a) new B(a).mul(c) a.multiply(c) A.multiply(a,c) a.multiply( new A(c) ) new B(a).multiply(c) |
a % b | a.remainder(b) A.remainder(a,b) a.remainder( new A(b) ) new B(a).remainder(b) |
a + b | a.add(b) A.add(a,b) a.add( new A(b) ) new B(a).add(b) |
a − b | a.sub(b) A.sub(a,b) a.sub( new A(b) ) new B(a).sub(b) a.subtract(b) A.subtract(a,b) a.subtract( new A(b) ) new B(a).subtract(b) c = new A(b).neg() c = new A(b).negate() c = b.neg() c = b.negate() followed by a.add(c) A.add(a,c) a.add( new A(c) ) new B(a).add(c) |