Fix previous commit losing sign in fractional numbers

This commit is contained in:
DBotThePony 2023-03-13 10:05:20 +07:00
parent de67209d24
commit 5626ca22d8
Signed by: DBot
GPG Key ID: DCC23B5715498507

View File

@ -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 {