Feature Request: Auto-Import kotlin.js.Math


While writing some code designed to work on both platforms (JVM & JS), I realized that Math functions can’t be accessed from the JS implementation without first importing kotlin.js.Math. This causes .kt files that should otherwise compile seamlessly on both platforms to suddenly require a platform-specific tweak for things like Math.pow() and Math.random(), even though they exist in both implementations!

Is there a reason kotlin.js.Math can’t be automatically imported like other packages? The ability to re-use more code between projects is one of the major benefits of having a JavaScript implementation in the first place, and this seems like an odd place to lose out on that.

This request probably also applies to Kotlin Native, assuming it has a similar Math package.


this was done intentionally in 1.1 for reasons. See https://youtrack.jetbrains.com/issue/KT-16175
btw kotlin.js.Math does not have the same interface as java.lang.Math


In Kotlin 1.2 we’re going to deprecate kotlin.js.Math class in order to remove it later. The replacement functions will be provided in kotlin.math package, which is available on both platforms.