Cannot find multiplatform arithmetic operations si...
# multiplatform
a
Cannot find multiplatform arithmetic operations similar to Java's https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/Math.html#addExact(long,long) Think it would be great to have arithmetic overflow handling for kotlin multiplatform.
e
I implemented some of these for Island Time (https://github.com/erikc5000/island-time), though they're internal to the library. It uses the Java methods on JVM and a pure Kotlin implementation (partially adapted from threetenbp) for the other platforms. Have a look at internal/Math.kt if you're interested. The pure Kotlin implementations are pretty slow, unfortunately. I experimented with calling into native C code using the compiler built-ins for checked arithmetic, but the call overhead from K/N seems to far outweigh any benefits. It'd be nice to have this in the standard library. I imagine that would make it possible to add some intrinsics to use the built-ins directly in the generated code, significantly improving the performance.