When compacting, if value is 0 then make divisor 1

This commit is contained in:
DBotThePony 2021-12-23 23:43:15 +07:00
parent 45132af065
commit f8f0ac27b4
Signed by: DBot
GPG Key ID: DCC23B5715498507

View File

@ -158,6 +158,10 @@ data class Fraction @JvmOverloads constructor(@JvmField val value: BigInteger, @
return Fraction(value + other.value)
val new = value + other.value
if (new.compareTo(BigInteger.ZERO) == 0)
return ZERO
val mod = new % divisor
if (mod == BigInteger.ZERO)
@ -193,6 +197,10 @@ data class Fraction @JvmOverloads constructor(@JvmField val value: BigInteger, @
return Fraction(value - other.value)
val new = value - other.value
if (new.compareTo(BigInteger.ZERO) == 0)
return ZERO
val mod = new % divisor
if (mod == BigInteger.ZERO)
@ -224,6 +232,10 @@ data class Fraction @JvmOverloads constructor(@JvmField val value: BigInteger, @
fun timesCompact(other: Fraction): Fraction {
val new = value * other.value
if (new.compareTo(BigInteger.ZERO) == 0)
return ZERO
val div = divisor * other.divisor
val mod = new % div
@ -242,6 +254,10 @@ data class Fraction @JvmOverloads constructor(@JvmField val value: BigInteger, @
fun divCompact(other: Fraction): Fraction {
val new = value * other.divisor
if (new.compareTo(BigInteger.ZERO) == 0)
return ZERO
val div = divisor * other.value
val mod = new % div