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 {
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user