diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/core/Fraction.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/core/Fraction.kt index 259c06936..a2ef2f9b5 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/core/Fraction.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/core/Fraction.kt @@ -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