If you write Kotlin Multiplatform code that involves integer division, you may have already hit this: the exact same expression behaves completely differently depending on which platform compiles it.
🐛 The problem
Take this innocuous expression:
val quotient = 12 / 0
val remainder = 12 % 0
On JVM and Native, both lines throw an ArithmeticException. That is the behavior most Kotlin developers expect and design around.
On JavaScript, both lines execute without any exception and silently return 0.
Here is a concrete illustration drawn directly from the Kotlin test suites for each platform:
// Kotlin/JS
check(12 / 0 == 0) // passes — no exception
check(12 % 0 == 0) // passes — no exception
// Kotlin/JVM and Kotlin/Native
val quotient: Result<Int> = runCatching { 12 / 0 }
val remainder: Result<Int> = runCatching { 12 % 0 }
check(quotient.exceptionOrNull() is ArithmeticException) // passes
check(remainder.exceptionOrNull() is ArithmeticExce
Discussion
Take the lead—comment now
Lead the way—your insights can inspire others.