https://kotlinlang.org logo
#announcements
Title
# announcements
r

Ruckus

09/23/2019, 2:27 PM
Is it intentional that values in the
Double.Companion
are not
const
? I cannot do
const val USE_DEFAULT = Double.NEGATIVE_INFINITY
.
s

Shawn

09/23/2019, 5:27 PM
it’s been a while since I’ve mucked about with this but there may just be too much uncertainty about how representations of +/- inf and NaN are implemented on various platforms to make it a value that can be safely selected and inlined by the compiler. That said, I truly don’t know much about computers so take this w/ a grain of salt lol
k

karelpeeters

09/23/2019, 7:59 PM
That's true for some other languages (C++, Python, ...) but primitives on the JVM and JS are fully specified up to the bit level to be IEEE floating points.
s

Shawn

09/23/2019, 8:00 PM
I figured as much, but multiplatform/native might complicate things there? Honestly not sure how that shakes out
k

karelpeeters

09/23/2019, 8:01 PM
I'm not familiar with Native but the docs say it's IEEE so I think that's guaranteed: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-float/index.html
👍 2
d

Davio

09/24/2019, 7:19 AM
It could be because some "const" numbers are not easily expressed in Kotlin? For instance, Double.MIN_VALUE in Java has the hexadecimal literal
0x0.0000000000001P-1022
with the suffix 'P' being the Binary Exponent indicator, so this is 'just' 2^-1074; the binary exponent indicator does not exist in Kotlin so it would be hard to express this number with a literal, making it impossible / improbable to do it with a const
r

Ruckus

09/24/2019, 1:38 PM
I don't see how that's a factor...
k

karelpeeters

09/24/2019, 4:06 PM
The more I think about it the more I think it's just a bug/mistake. I guess it's pretty rare to use
NEGATIVE_INFINITY
in an annotation and you're the first to run into it?
r

Ruckus

09/25/2019, 12:12 AM
Could be. I'll try to remember to file a bug tomorrow and see what shakes out.
3 Views