3

There is a library called kotlin.math which contains a method pow:

import kotlin.math.pow
val factor = pow(10.0, 2)
print(factor)

and result:

100.0

However Intellij is not registering that I have imported the pow function, is there a special pow method for KotlinJS?

Robbie Cronin
  • 1,557
  • 2
  • 10
  • 15

1 Answers1

6

There are two different versions of pow in KotlinJS.

The deprecated kotlin.js.math.pow which is defined as:

public fun pow(base: Double, exp: Double): Double

and the standard library version kotlin.math.pow which is defined as an extension function.

public actual inline fun Double.pow(n: Int): Double = nativeMath.pow(this, n.toDouble())

So your example has to be changed to look like this:

import kotlin.math.pow
val factor = 10.0.pow(2)
print(factor)
Alexander Egger
  • 5,132
  • 1
  • 28
  • 42