Shortcuts for when current decimal is zero
This commit is contained in:
parent
8653dd343f
commit
2720f6fbf0
@ -202,7 +202,7 @@ class Decimal private constructor(val mag: BigInteger, marker: Nothing?) : Numbe
|
|||||||
operator fun times(other: Float): Decimal {
|
operator fun times(other: Float): Decimal {
|
||||||
if (other == 1f) {
|
if (other == 1f) {
|
||||||
return this
|
return this
|
||||||
} else if (other == 0f) {
|
} else if (other == 0f || isZero) {
|
||||||
return ZERO
|
return ZERO
|
||||||
} else if (other == -1f) {
|
} else if (other == -1f) {
|
||||||
return -this
|
return -this
|
||||||
@ -218,7 +218,7 @@ class Decimal private constructor(val mag: BigInteger, marker: Nothing?) : Numbe
|
|||||||
operator fun div(other: Float): Decimal {
|
operator fun div(other: Float): Decimal {
|
||||||
if (other == 0f) {
|
if (other == 0f) {
|
||||||
throw ArithmeticException("Attempt to divide $this by zero")
|
throw ArithmeticException("Attempt to divide $this by zero")
|
||||||
} else if (other == 1f) {
|
} else if (other == 1f || isZero) {
|
||||||
return this
|
return this
|
||||||
} else if (other == -1f) {
|
} else if (other == -1f) {
|
||||||
return -this
|
return -this
|
||||||
@ -258,7 +258,7 @@ class Decimal private constructor(val mag: BigInteger, marker: Nothing?) : Numbe
|
|||||||
operator fun times(other: Double): Decimal {
|
operator fun times(other: Double): Decimal {
|
||||||
if (other == 1.0) {
|
if (other == 1.0) {
|
||||||
return this
|
return this
|
||||||
} else if (other == 0.0) {
|
} else if (other == 0.0 || isZero) {
|
||||||
return ZERO
|
return ZERO
|
||||||
} else if (other == -1.0) {
|
} else if (other == -1.0) {
|
||||||
return -this
|
return -this
|
||||||
@ -274,7 +274,7 @@ class Decimal private constructor(val mag: BigInteger, marker: Nothing?) : Numbe
|
|||||||
operator fun div(other: Double): Decimal {
|
operator fun div(other: Double): Decimal {
|
||||||
if (other == 0.0) {
|
if (other == 0.0) {
|
||||||
throw ArithmeticException("Attempt to divide $this by zero")
|
throw ArithmeticException("Attempt to divide $this by zero")
|
||||||
} else if (other == 1.0) {
|
} else if (other == 1.0 || isZero) {
|
||||||
return this
|
return this
|
||||||
} else if (other == -1.0) {
|
} else if (other == -1.0) {
|
||||||
return -this
|
return -this
|
||||||
@ -304,7 +304,7 @@ class Decimal private constructor(val mag: BigInteger, marker: Nothing?) : Numbe
|
|||||||
}
|
}
|
||||||
|
|
||||||
operator fun times(other: Int): Decimal {
|
operator fun times(other: Int): Decimal {
|
||||||
if (other == 1) {
|
if (other == 1 || isZero) {
|
||||||
return this
|
return this
|
||||||
} else if (other == 0) {
|
} else if (other == 0) {
|
||||||
return ZERO
|
return ZERO
|
||||||
@ -318,7 +318,7 @@ class Decimal private constructor(val mag: BigInteger, marker: Nothing?) : Numbe
|
|||||||
operator fun div(other: Int): Decimal {
|
operator fun div(other: Int): Decimal {
|
||||||
if (other == 0) {
|
if (other == 0) {
|
||||||
throw ArithmeticException("Attempt to divide $this by zero")
|
throw ArithmeticException("Attempt to divide $this by zero")
|
||||||
} else if (other == 1) {
|
} else if (other == 1 || signum() == 0) {
|
||||||
return this
|
return this
|
||||||
} else if (other == -1) {
|
} else if (other == -1) {
|
||||||
return -this
|
return -this
|
||||||
@ -344,7 +344,7 @@ class Decimal private constructor(val mag: BigInteger, marker: Nothing?) : Numbe
|
|||||||
}
|
}
|
||||||
|
|
||||||
operator fun times(other: Long): Decimal {
|
operator fun times(other: Long): Decimal {
|
||||||
if (other == 1L) {
|
if (other == 1L || isZero) {
|
||||||
return this
|
return this
|
||||||
} else if (other == 0L) {
|
} else if (other == 0L) {
|
||||||
return ZERO
|
return ZERO
|
||||||
@ -358,7 +358,7 @@ class Decimal private constructor(val mag: BigInteger, marker: Nothing?) : Numbe
|
|||||||
operator fun div(other: Long): Decimal {
|
operator fun div(other: Long): Decimal {
|
||||||
if (other == 0L) {
|
if (other == 0L) {
|
||||||
throw ArithmeticException("Attempt to divide $this by zero")
|
throw ArithmeticException("Attempt to divide $this by zero")
|
||||||
} else if (other == 1L) {
|
} else if (other == 1L || isZero) {
|
||||||
return this
|
return this
|
||||||
} else if (other == -1L) {
|
} else if (other == -1L) {
|
||||||
return -this
|
return -this
|
||||||
@ -386,7 +386,7 @@ class Decimal private constructor(val mag: BigInteger, marker: Nothing?) : Numbe
|
|||||||
operator fun times(other: BigInteger): Decimal {
|
operator fun times(other: BigInteger): Decimal {
|
||||||
if (other == BigInteger.ONE) {
|
if (other == BigInteger.ONE) {
|
||||||
return this
|
return this
|
||||||
} else if (other.signum() == 0) {
|
} else if (other.signum() == 0 || isZero) {
|
||||||
return ZERO
|
return ZERO
|
||||||
} else if (other == BI_MINUS_ONE) {
|
} else if (other == BI_MINUS_ONE) {
|
||||||
return -this
|
return -this
|
||||||
@ -398,7 +398,7 @@ class Decimal private constructor(val mag: BigInteger, marker: Nothing?) : Numbe
|
|||||||
operator fun div(other: BigInteger): Decimal {
|
operator fun div(other: BigInteger): Decimal {
|
||||||
if (other == BigInteger.ZERO) {
|
if (other == BigInteger.ZERO) {
|
||||||
throw ArithmeticException("Attempt to divide $this by zero")
|
throw ArithmeticException("Attempt to divide $this by zero")
|
||||||
} else if (other == BigInteger.ONE) {
|
} else if (other == BigInteger.ONE || isZero) {
|
||||||
return this
|
return this
|
||||||
} else if (other == BI_MINUS_ONE) {
|
} else if (other == BI_MINUS_ONE) {
|
||||||
return -this
|
return -this
|
||||||
|
Loading…
Reference in New Issue
Block a user