From 5626ca22d8d378c2916fa4b3ddca276e9416b89e Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Mon, 13 Mar 2023 10:05:20 +0700 Subject: [PATCH] Fix previous commit losing sign in fractional numbers --- .../kotlin/ru/dbotthepony/mc/otm/core/math/Decimal.kt | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) 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 f6efc24fd..8edc18204 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 @@ -605,8 +605,16 @@ class Decimal @JvmOverloads constructor(whole: BigInteger, decimal: Double = 0.0 return BigDecimal(whole) + BigDecimal(decimal) } + private var _signum = Int.MIN_VALUE + fun signum(): Int { - return whole.signum() + if (_signum == Int.MIN_VALUE) { + var cmp = whole.signum() + if (cmp == 0) cmp = if (decimal == 0.0) 0 else if (1.0 / decimal > 0.0) 1 else -1 + _signum = cmp + } + + return _signum } override fun compareTo(other: Decimal): Int {