mirror of
https://github.com/DanilaFe/abacus
synced 2024-11-18 00:19:32 -08:00
Add operator overloading.
This commit is contained in:
parent
bc475a22f9
commit
4fd8f7badf
|
@ -230,4 +230,39 @@ abstract class NumberInterface: Comparable<NumberInterface> {
|
|||
*/
|
||||
operator fun rangeTo(other: NumberInterface) = NumberRangeBuilder(this, other)
|
||||
|
||||
/**
|
||||
* Plus operator overloaded to allow "nice" looking math.
|
||||
* @param other the value to add to this number.
|
||||
* @return the result of the addition.
|
||||
*/
|
||||
operator fun plus(other: NumberInterface) = add(other)
|
||||
/**
|
||||
* Minus operator overloaded to allow "nice" looking math.
|
||||
* @param other the value to subtract to this number.
|
||||
* @return the result of the subtraction.
|
||||
*/
|
||||
operator fun minus(other: NumberInterface) = subtract(other)
|
||||
/**
|
||||
* Times operator overloaded to allow "nice" looking math.
|
||||
* @param other the value to multiply this number by.
|
||||
* @return the result of the multiplication.
|
||||
*/
|
||||
operator fun times(other: NumberInterface) = multiply(other)
|
||||
/**
|
||||
* Divide operator overloaded to allow "nice" looking math.
|
||||
* @param other the value to divide this number by.
|
||||
* @return the result of the division.
|
||||
*/
|
||||
operator fun div(other: NumberInterface) = divide(other)
|
||||
/**
|
||||
* The plus operator.
|
||||
* @return this number.
|
||||
*/
|
||||
operator fun unaryPlus() = this
|
||||
/**
|
||||
* The minus operator.
|
||||
* @return the negative of this number.
|
||||
*/
|
||||
operator fun unaryMinus() = negate()
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user