Hullaballoonatic
06/14/2019, 12:24 AMNumber
not operable in the JVM? Why did Sun design it that way and why does JB not fix it in Kotlin? Everything (afaik) that inherits from Number
is operable, so why wouldn't the operators be refactored to be included there?Shawn
06/14/2019, 1:37 AM4 + NaN
equal?Hullaballoonatic
06/14/2019, 3:09 AMShawn
06/14/2019, 3:10 AMShawn
06/14/2019, 3:10 AMShawn
06/14/2019, 3:10 AMHullaballoonatic
06/14/2019, 3:10 AMerror("You cannot add NaN to a number")
Hullaballoonatic
06/14/2019, 3:11 AMShawn
06/14/2019, 3:12 AMShawn
06/14/2019, 3:12 AM4.0
, NaN
, and 6.9
are all valid float values - you can’t vary the return type of a function based on the value of its argumentsHullaballoonatic
06/14/2019, 3:12 AMNumber
class has the following added:
abstract operator fun <N: Number> plus(other: N): N
// etc for others
Hullaballoonatic
06/14/2019, 3:13 AMHullaballoonatic
06/14/2019, 3:14 AMShawn
06/14/2019, 3:14 AMHullaballoonatic
06/14/2019, 3:15 AMNumber
become
abstract class Number<N: Number<N>>()
and therefore you can only do the operations on a number of the same typeHullaballoonatic
06/14/2019, 3:15 AMHullaballoonatic
06/14/2019, 3:15 AMHullaballoonatic
06/14/2019, 3:16 AMShawn
06/14/2019, 3:16 AMHullaballoonatic
06/14/2019, 3:16 AMShawn
06/14/2019, 3:18 AMShawn
06/14/2019, 3:19 AMHullaballoonatic
06/14/2019, 3:23 AMShawn
06/14/2019, 3:24 AMHullaballoonatic
06/14/2019, 3:24 AMHullaballoonatic
06/14/2019, 3:25 AMfun adder<N: Number>(a: N, b: N): N = a + b
Hullaballoonatic
06/14/2019, 3:25 AMShawn
06/14/2019, 3:26 AMNumber
Shawn
06/14/2019, 3:27 AM(int) 4
Hullaballoonatic
06/14/2019, 3:27 AMShawn
06/14/2019, 3:28 AMShawn
06/14/2019, 3:28 AMfloat
up to a BigDecimal
?Shawn
06/14/2019, 3:29 AMNumber
throughout, that seems like a nightmare to debugShawn
06/14/2019, 3:29 AMShawn
06/14/2019, 3:30 AMShawn
06/14/2019, 3:30 AMShawn
06/14/2019, 3:32 AMadder()
function as is - just with a lot of runtime typecheckingShawn
06/14/2019, 3:34 AMreturn when (lhs) {
is Double -> when (rhs) {
is Double -> lhs + rhs // return a Double, but it's a Number™