When compacting, if value is 0 then make divisor 1
This commit is contained in:
parent
45132af065
commit
f8f0ac27b4
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user