Extended documentation, code refactoring, API consistency changes #125
@ -24,9 +24,36 @@ interface MathWrapper<T, I> {
|
||||
* @param S the type of space
|
||||
*/
|
||||
interface SpaceElement<T, I : SpaceElement<T, I, S>, S : Space<T>> : MathElement<S>, MathWrapper<T, I> {
|
||||
/**
|
||||
* Adds element to this one.
|
||||
*
|
||||
* @param b the augend.
|
||||
* @return the sum.
|
||||
*/
|
||||
operator fun plus(b: T): I = context.add(unwrap(), b).wrap()
|
||||
|
||||
/**
|
||||
* Subtracts element from this one.
|
||||
*
|
||||
* @param b the subtrahend.
|
||||
* @return the difference.
|
||||
*/
|
||||
operator fun minus(b: T): I = context.add(unwrap(), context.multiply(b, -1.0)).wrap()
|
||||
|
||||
/**
|
||||
* Multiplies this element by number.
|
||||
*
|
||||
* @param k the multiplicand.
|
||||
* @return the product.
|
||||
*/
|
||||
operator fun times(k: Number): I = context.multiply(unwrap(), k.toDouble()).wrap()
|
||||
|
||||
/**
|
||||
* Divides this element by number.
|
||||
*
|
||||
* @param k the divisor.
|
||||
* @return the quotient.
|
||||
*/
|
||||
operator fun div(k: Number): I = context.multiply(unwrap(), 1.0 / k.toDouble()).wrap()
|
||||
}
|
||||
|
||||
@ -34,6 +61,12 @@ interface SpaceElement<T, I : SpaceElement<T, I, S>, S : Space<T>> : MathElement
|
||||
* Ring element
|
||||
*/
|
||||
interface RingElement<T, I : RingElement<T, I, R>, R : Ring<T>> : SpaceElement<T, I, R> {
|
||||
/**
|
||||
* Multiplies this element by another one.
|
||||
*
|
||||
* @param b the multiplicand.
|
||||
* @return the product.
|
||||
*/
|
||||
operator fun times(b: T): I = context.multiply(unwrap(), b).wrap()
|
||||
}
|
||||
|
||||
@ -42,5 +75,12 @@ interface RingElement<T, I : RingElement<T, I, R>, R : Ring<T>> : SpaceElement<T
|
||||
*/
|
||||
interface FieldElement<T, I : FieldElement<T, I, F>, F : Field<T>> : RingElement<T, I, F> {
|
||||
override val context: F
|
||||
|
||||
/**
|
||||
* Divides this element by another one.
|
||||
*
|
||||
* @param b the divisor.
|
||||
* @return the quotient.
|
||||
*/
|
||||
operator fun div(b: T): I = context.divide(unwrap(), b).wrap()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user