From 2720f6fbf0efcf1ea6663147f825271d754a38b1 Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Wed, 2 Aug 2023 16:21:15 +0700 Subject: [PATCH] Shortcuts for when current decimal is zero --- .../dbotthepony/mc/otm/core/math/Decimal.kt | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/core/math/Decimal.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/core/math/Decimal.kt index e91bc36a9..3ed4e4750 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/core/math/Decimal.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/core/math/Decimal.kt @@ -202,7 +202,7 @@ class Decimal private constructor(val mag: BigInteger, marker: Nothing?) : Numbe operator fun times(other: Float): Decimal { if (other == 1f) { return this - } else if (other == 0f) { + } else if (other == 0f || isZero) { return ZERO } else if (other == -1f) { return -this @@ -218,7 +218,7 @@ class Decimal private constructor(val mag: BigInteger, marker: Nothing?) : Numbe operator fun div(other: Float): Decimal { if (other == 0f) { throw ArithmeticException("Attempt to divide $this by zero") - } else if (other == 1f) { + } else if (other == 1f || isZero) { return this } else if (other == -1f) { return -this @@ -258,7 +258,7 @@ class Decimal private constructor(val mag: BigInteger, marker: Nothing?) : Numbe operator fun times(other: Double): Decimal { if (other == 1.0) { return this - } else if (other == 0.0) { + } else if (other == 0.0 || isZero) { return ZERO } else if (other == -1.0) { return -this @@ -274,7 +274,7 @@ class Decimal private constructor(val mag: BigInteger, marker: Nothing?) : Numbe operator fun div(other: Double): Decimal { if (other == 0.0) { throw ArithmeticException("Attempt to divide $this by zero") - } else if (other == 1.0) { + } else if (other == 1.0 || isZero) { return this } else if (other == -1.0) { return -this @@ -304,7 +304,7 @@ class Decimal private constructor(val mag: BigInteger, marker: Nothing?) : Numbe } operator fun times(other: Int): Decimal { - if (other == 1) { + if (other == 1 || isZero) { return this } else if (other == 0) { return ZERO @@ -318,7 +318,7 @@ class Decimal private constructor(val mag: BigInteger, marker: Nothing?) : Numbe operator fun div(other: Int): Decimal { if (other == 0) { throw ArithmeticException("Attempt to divide $this by zero") - } else if (other == 1) { + } else if (other == 1 || signum() == 0) { return this } else if (other == -1) { return -this @@ -344,7 +344,7 @@ class Decimal private constructor(val mag: BigInteger, marker: Nothing?) : Numbe } operator fun times(other: Long): Decimal { - if (other == 1L) { + if (other == 1L || isZero) { return this } else if (other == 0L) { return ZERO @@ -358,7 +358,7 @@ class Decimal private constructor(val mag: BigInteger, marker: Nothing?) : Numbe operator fun div(other: Long): Decimal { if (other == 0L) { throw ArithmeticException("Attempt to divide $this by zero") - } else if (other == 1L) { + } else if (other == 1L || isZero) { return this } else if (other == -1L) { return -this @@ -386,7 +386,7 @@ class Decimal private constructor(val mag: BigInteger, marker: Nothing?) : Numbe operator fun times(other: BigInteger): Decimal { if (other == BigInteger.ONE) { return this - } else if (other.signum() == 0) { + } else if (other.signum() == 0 || isZero) { return ZERO } else if (other == BI_MINUS_ONE) { return -this @@ -398,7 +398,7 @@ class Decimal private constructor(val mag: BigInteger, marker: Nothing?) : Numbe operator fun div(other: BigInteger): Decimal { if (other == BigInteger.ZERO) { throw ArithmeticException("Attempt to divide $this by zero") - } else if (other == BigInteger.ONE) { + } else if (other == BigInteger.ONE || isZero) { return this } else if (other == BI_MINUS_ONE) { return -this