```fun main() { val num: Number = 25 print...
# stdlib
j
Copy code
fun main() {
    val num: Number = 25
    println(num > 10)
}
Shouldn't something like this be possible by the stdlib?
j
How would it be implemented?
I can create an infinite-precision
Number
subtype and represent a number outside the valid range of all available conversion functions
j
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
i think that means
0.2 > 0.1
would return false
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
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.