From 4fd8f7badf154efc562d614a8585a156fb6ebc2d Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Thu, 21 Sep 2017 13:25:05 -0700 Subject: [PATCH] Add operator overloading. --- .../nwapw/abacus/number/NumberInterface.kt | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/core/src/main/kotlin/org/nwapw/abacus/number/NumberInterface.kt b/core/src/main/kotlin/org/nwapw/abacus/number/NumberInterface.kt index c3f4d90..337969c 100644 --- a/core/src/main/kotlin/org/nwapw/abacus/number/NumberInterface.kt +++ b/core/src/main/kotlin/org/nwapw/abacus/number/NumberInterface.kt @@ -230,4 +230,39 @@ abstract class NumberInterface: Comparable { */ 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() + } \ No newline at end of file