diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/core/math/Decimal.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/core/math/Decimal.kt index 8edc18204..3332158ed 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/core/math/Decimal.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/core/math/Decimal.kt @@ -558,14 +558,8 @@ class Decimal @JvmOverloads constructor(whole: BigInteger, decimal: Double = 0.0 } override fun equals(other: Any?): Boolean { - if (isNaN) - return false - - if (other is Decimal) { - return other.whole == whole && decimal == other.decimal - } - - return super.equals(other) + if (isNaN) return false + return other === this || other is Decimal && other.whole == whole && weakEqualDoubles(decimal, other.decimal) } override fun hashCode(): Int { @@ -632,7 +626,7 @@ class Decimal @JvmOverloads constructor(whole: BigInteger, decimal: Double = 0.0 return 1 var cmp = whole.compareTo(other.whole) - if (cmp == 0) cmp = decimal.compareTo(other.decimal) + if (cmp == 0) cmp = weakCompareDoubles(decimal, other.decimal) return cmp } diff --git a/src/test/kotlin/ru/dbotthepony/mc/otm/tests/DecimalTests.kt b/src/test/kotlin/ru/dbotthepony/mc/otm/tests/DecimalTests.kt index 801639431..9f27dde91 100644 --- a/src/test/kotlin/ru/dbotthepony/mc/otm/tests/DecimalTests.kt +++ b/src/test/kotlin/ru/dbotthepony/mc/otm/tests/DecimalTests.kt @@ -30,7 +30,7 @@ object DecimalTests { check((Decimal(0, 0.5) + Decimal(0, 0.5)) == Decimal(1)) { "0.5 + 0.5 != 1" } check((Decimal(0, 0.5) + Decimal(0, -0.5)) == Decimal(0)) { "0.5 + -0.5 != 1" } check((Decimal(0, 0.5) - Decimal(0, -0.5)) == Decimal(1)) { "0.5 - -0.5 != 1" } - check((Decimal(0, 0.3) - Decimal(1, 0.2)) == Decimal(0, -0.9)) { "0.3 - 1.2 != -0.9" } + check((Decimal(0, 0.3) - Decimal(1, 0.2)) == Decimal(0, -0.9)) { "0.3 - 1.2 != -0.9 ${Decimal(0, -0.9)} ${Decimal(0, 0.3) - Decimal(1, 0.2)}" } check((Decimal(0, 0.3) * Decimal(0, 0.3)) == Decimal(0, 0.09)) { "0.3 * 0.3 != 0.9 ${Decimal(0, 0.3) * Decimal(0, 0.3)}" } check((Decimal(2, 0.3) * Decimal(2, 0.3)) == Decimal(5, 0.29)) { "2.3 * 2.3 != 5.29 ${Decimal(2, 0.3) * Decimal(2, 0.3)}" } check((Decimal(4) / Decimal(2)) == Decimal(2)) { "4 / 2 != 2" }