Is this behaviour documented anywhere? Why does re...
# announcements
j
Is this behaviour documented anywhere? Why does reallyReallyReallyLong become zero? Does the result after multiplication simply get truncated to 64 bits?
d
If the result is greater than
Long.MAX_VALUE
, it will silently overflow just like
long
in java. Documented Somewhat documented here https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html for JVM and I assume it works in a similar way on other platforms. It might be a good idea to have more documentation to make adoption by non-java programmers easier.
j
I have been programming Java for 15 years, have seen integer and long multiplication roll over into the negatives all the time, and yet somehow when I ran into the case above I immediately forgot all that and wondered why it didn't throw an exception... Thanks @Dmitry Kandalov and @karelpeeters
👍 2
e
It actually gives you a warning in IDEA.
👍 3
j
Oh that's neat! I tested this on play.kotlinlang.org and I don't recall seeing such a warning there
e
Generally, programming in IDEA is way better that in any online editor or other kind of editor. You get much more insight into your code.
1