why is `Number` so limited? why doesn't it look so...
# announcements
h
why is
Number
so limited? why doesn't it look something like this, at the very least?
Copy code
interface Number<N: Number<N> : Comparable<N> {
    operator fun plus(other: N): N
    operator fun minus(other: N): N
    operator fun times(other: N): N
    operator fun div(other: N): N
    operator fun unaryMinus(): N

    val minValue: N
    val maxValue: N

    fun inverse(): N

    fun toDouble(): Double
    fun toFloat(): Float
    fun toLong(): Long
    fun toInt(): Int
    fun toChar(): Char
    fun toShort(): Short
    fun toByte(): Byte
}
am i wrong in thinking all subclasses of Number implement those operators anyways?
d
The main issue is the JVM limits the
Number
class. Not much can be done if 100% interop is desired.
Also, those operators introduce a fair bit of boxing, because generics.
🗃️ 2
h
so i guess the happy-medium is for
Number
really is, simply, to have functions to convert them to operable number types?
d
Yeah I guess so. It's especially weird, since programmers tend to avoid using the subclasses anyway and use the primitive equivalent.
a
Not saying that it is the reason, but
Complex
number is not comparable in mathematical sense and so it does not have minValue and maxValue.
z
Ideally (imo)
Number
would not be an interface but something like a typeclass (KEEP-87), so that it could be used with all the existing numerical types. I bet #C5UPMM0A0 already has something like this 😂
☝🏼 1
😂 1