fun main() {
val num: Number = 25
println(num > 10)
}
Shouldn't something like this be possible by the stdlib?
j
jw
11/10/2022, 5:43 PM
How would it be implemented?
jw
11/10/2022, 5:43 PM
I can create an infinite-precision
Number
subtype and represent a number outside the valid range of all available conversion functions
j
jeggy
11/10/2022, 5:45 PM
Copy code
operator fun Number.compareTo(i: Int) = toLong().compareTo(i.toLong())
operator fun Number.compareTo(i: Long) = toLong().compareTo(i)
I created these
j
jw
11/10/2022, 5:46 PM
i think that means
0.2 > 0.1
would return false
jw
11/10/2022, 5:47 PM
It also will return false for really high values of
BigInteger
given its
longValue()
implementation states:
if this BigInteger is too big to fit in a long, only the low-order 64 bits are returned.
a
andries.fc
11/15/2022, 8:31 AM
Problem is the number class has not to indicate the precision of the number. To make a comparison you have to convert to the lowest precision of the two numbers.