:warning: *The Kotlin Multiplatform division-by-ze...
# feed
l
⚠️ The Kotlin Multiplatform division-by-zero trap:
12 / 0
behaves differently on every platform
On Kotlin/JS,
12 / 0
silently returns
0
. On JVM and Native it throws
ArithmeticException
. That guard you wrote and tested on JVM? It is silently bypassed when the same code runs on JS. We wrote a short post about what causes this and how the
Integer
type in Kotools Types 5.1.1 fixes it consistently across all three targets — including null-safe
divOrNull
and
remOrNull
variants for those who prefer not to catch exceptions. Read it here 👇
🤦‍♂️ 3
👀 1
d
TIL. Thanks, Out of curiosity, shouldn't this be considered a bug of K/JS? Is there a ticket open in Koltin's YouTrack?
m
What's the behavior of WASM? Just curious.
e
exception, because wasm has actual ints. JS doesn't, everything is a Number (Double)
thank you color 1
you can easily try it out for yourself https://pl.kotl.in/XCdt-SsbQ https://pl.kotl.in/c5NndZ0Jy
thank you color 1