pow

expect fun Double.pow(x: Double): Double(source)

Raises this value to the power x.

Special cases:

  • b.pow(0.0) is 1.0

  • b.pow(1.0) == b

  • b.pow(NaN) is NaN

  • NaN.pow(x) is NaN for x != 0.0

  • b.pow(Inf) is NaN for abs(b) == 1.0

  • b.pow(x) is NaN for b < 0 and x is finite and not an integer

Since Kotlin

1.2

Samples

import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   println(2.0.pow(2.0)) // 4.0
println(3.0.pow(1.0)) // 3.0
println(4.0.pow(0.0)) // 1.0
println(2.0.pow(-2.0)) // 0.25
println(4.0.pow(0.5)) // 2.0
println((-2.0).pow(2.0)) // 4.0

// special cases
println(Double.NaN.pow(42.0)) // NaN
println(Double.NaN.pow(0.0)) // 1.0
println(3.0.pow(Double.NaN)) // NaN
println((-2.0).pow(0.75)) // NaN
println(1.0.pow(Double.POSITIVE_INFINITY)) // NaN
println(1.0.pow(Double.NEGATIVE_INFINITY)) // NaN
println(2.0.pow(Double.POSITIVE_INFINITY)) // Infinity
println(2.0.pow(Double.NEGATIVE_INFINITY)) // 0.0 
   //sampleEnd
}

expect fun Double.pow(n: Int): Double(source)

Raises this value to the integer power n.

See the other overload of pow for details.

Since Kotlin

1.2

Samples

import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   println(2.0.pow(2)) // 4.0
println(3.0.pow(1)) // 3.0
println(4.0.pow(0)) // 1.0
println(2.0.pow(-2)) // 0.25
println((-2.0).pow(2)) // 4.0

// special cases
println(Double.NaN.pow(42)) // NaN
println(Double.NaN.pow(0)) // 1.0 
   //sampleEnd
}

expect fun Float.pow(x: Float): Float(source)

Raises this value to the power x.

Special cases:

  • b.pow(0.0) is 1.0

  • b.pow(1.0) == b

  • b.pow(NaN) is NaN

  • NaN.pow(x) is NaN for x != 0.0

  • b.pow(Inf) is NaN for abs(b) == 1.0

  • b.pow(x) is NaN for b < 0 and x is finite and not an integer

Since Kotlin

1.2

Samples

import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   println(2.0f.pow(2.0f)) // 4.0
println(3.0f.pow(1.0f)) // 3.0
println(4.0f.pow(0.0f)) // 1.0
println(2.0f.pow(-2.0f)) // 0.25
println(4.0f.pow(0.5f)) // 2.0
println((-2.0f).pow(2.0f)) // 4.0

// special cases
println(Float.NaN.pow(42.0f)) // NaN
println(Float.NaN.pow(0.0f)) // 1.0
println(3.0f.pow(Float.NaN)) // NaN
println((-2.0f).pow(0.75f)) // NaN
println(1.0f.pow(Float.POSITIVE_INFINITY)) // NaN
println(1.0f.pow(Float.NEGATIVE_INFINITY)) // NaN
println(2.0f.pow(Float.POSITIVE_INFINITY)) // Infinity
println(2.0f.pow(Float.NEGATIVE_INFINITY)) // 0.0 
   //sampleEnd
}

expect fun Float.pow(n: Int): Float(source)

Raises this value to the integer power n.

See the other overload of pow for details.

Since Kotlin

1.2

Samples

import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   println(2.0f.pow(2)) // 4.0
println(3.0f.pow(1)) // 3.0
println(4.0f.pow(0)) // 1.0
println(2.0f.pow(-2)) // 0.25
println((-2.0f).pow(2)) // 4.0

// special cases
println(Float.NaN.pow(42)) // NaN
println(Float.NaN.pow(0)) // 1.0 
   //sampleEnd
}
actual inline fun Double.pow(x: Double): Double(source)

Raises this value to the power x.

Special cases:

  • b.pow(0.0) is 1.0

  • b.pow(1.0) == b

  • b.pow(NaN) is NaN

  • NaN.pow(x) is NaN for x != 0.0

  • b.pow(Inf) is NaN for abs(b) == 1.0

  • b.pow(x) is NaN for b < 0 and x is finite and not an integer

Since Kotlin

1.2

Samples

import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   println(2.0.pow(2.0)) // 4.0
println(3.0.pow(1.0)) // 3.0
println(4.0.pow(0.0)) // 1.0
println(2.0.pow(-2.0)) // 0.25
println(4.0.pow(0.5)) // 2.0
println((-2.0).pow(2.0)) // 4.0

// special cases
println(Double.NaN.pow(42.0)) // NaN
println(Double.NaN.pow(0.0)) // 1.0
println(3.0.pow(Double.NaN)) // NaN
println((-2.0).pow(0.75)) // NaN
println(1.0.pow(Double.POSITIVE_INFINITY)) // NaN
println(1.0.pow(Double.NEGATIVE_INFINITY)) // NaN
println(2.0.pow(Double.POSITIVE_INFINITY)) // Infinity
println(2.0.pow(Double.NEGATIVE_INFINITY)) // 0.0 
   //sampleEnd
}

actual inline fun Double.pow(n: Int): Double(source)

Raises this value to the integer power n.

See the other overload of pow for details.

Since Kotlin

1.2

Samples

import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   println(2.0.pow(2)) // 4.0
println(3.0.pow(1)) // 3.0
println(4.0.pow(0)) // 1.0
println(2.0.pow(-2)) // 0.25
println((-2.0).pow(2)) // 4.0

// special cases
println(Double.NaN.pow(42)) // NaN
println(Double.NaN.pow(0)) // 1.0 
   //sampleEnd
}

actual inline fun Float.pow(x: Float): Float(source)

Raises this value to the power x.

Special cases:

  • b.pow(0.0) is 1.0

  • b.pow(1.0) == b

  • b.pow(NaN) is NaN

  • NaN.pow(x) is NaN for x != 0.0

  • b.pow(Inf) is NaN for abs(b) == 1.0

  • b.pow(x) is NaN for b < 0 and x is finite and not an integer

Since Kotlin

1.2

Samples

import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   println(2.0f.pow(2.0f)) // 4.0
println(3.0f.pow(1.0f)) // 3.0
println(4.0f.pow(0.0f)) // 1.0
println(2.0f.pow(-2.0f)) // 0.25
println(4.0f.pow(0.5f)) // 2.0
println((-2.0f).pow(2.0f)) // 4.0

// special cases
println(Float.NaN.pow(42.0f)) // NaN
println(Float.NaN.pow(0.0f)) // 1.0
println(3.0f.pow(Float.NaN)) // NaN
println((-2.0f).pow(0.75f)) // NaN
println(1.0f.pow(Float.POSITIVE_INFINITY)) // NaN
println(1.0f.pow(Float.NEGATIVE_INFINITY)) // NaN
println(2.0f.pow(Float.POSITIVE_INFINITY)) // Infinity
println(2.0f.pow(Float.NEGATIVE_INFINITY)) // 0.0 
   //sampleEnd
}

actual inline fun Float.pow(n: Int): Float(source)

Raises this value to the integer power n.

See the other overload of pow for details.

Since Kotlin

1.2

Samples

import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   println(2.0f.pow(2)) // 4.0
println(3.0f.pow(1)) // 3.0
println(4.0f.pow(0)) // 1.0
println(2.0f.pow(-2)) // 0.25
println((-2.0f).pow(2)) // 4.0

// special cases
println(Float.NaN.pow(42)) // NaN
println(Float.NaN.pow(0)) // 1.0 
   //sampleEnd
}
actual inline fun Double.pow(x: Double): Double(source)

Raises this value to the power x.

Special cases:

  • b.pow(0.0) is 1.0

  • b.pow(1.0) == b

  • b.pow(NaN) is NaN

  • NaN.pow(x) is NaN for x != 0.0

  • b.pow(Inf) is NaN for abs(b) == 1.0

  • b.pow(x) is NaN for b < 0 and x is finite and not an integer

Since Kotlin

1.2

Samples

import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   println(2.0.pow(2.0)) // 4.0
println(3.0.pow(1.0)) // 3.0
println(4.0.pow(0.0)) // 1.0
println(2.0.pow(-2.0)) // 0.25
println(4.0.pow(0.5)) // 2.0
println((-2.0).pow(2.0)) // 4.0

// special cases
println(Double.NaN.pow(42.0)) // NaN
println(Double.NaN.pow(0.0)) // 1.0
println(3.0.pow(Double.NaN)) // NaN
println((-2.0).pow(0.75)) // NaN
println(1.0.pow(Double.POSITIVE_INFINITY)) // NaN
println(1.0.pow(Double.NEGATIVE_INFINITY)) // NaN
println(2.0.pow(Double.POSITIVE_INFINITY)) // Infinity
println(2.0.pow(Double.NEGATIVE_INFINITY)) // 0.0 
   //sampleEnd
}

actual inline fun Double.pow(n: Int): Double(source)

Raises this value to the integer power n.

See the other overload of pow for details.

Since Kotlin

1.2

Samples

import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   println(2.0.pow(2)) // 4.0
println(3.0.pow(1)) // 3.0
println(4.0.pow(0)) // 1.0
println(2.0.pow(-2)) // 0.25
println((-2.0).pow(2)) // 4.0

// special cases
println(Double.NaN.pow(42)) // NaN
println(Double.NaN.pow(0)) // 1.0 
   //sampleEnd
}

actual inline fun Float.pow(x: Float): Float(source)

Raises this value to the power x.

Special cases:

  • b.pow(0.0) is 1.0

  • b.pow(1.0) == b

  • b.pow(NaN) is NaN

  • NaN.pow(x) is NaN for x != 0.0

  • b.pow(Inf) is NaN for abs(b) == 1.0

  • b.pow(x) is NaN for b < 0 and x is finite and not an integer

Since Kotlin

1.2

Samples

import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   println(2.0f.pow(2.0f)) // 4.0
println(3.0f.pow(1.0f)) // 3.0
println(4.0f.pow(0.0f)) // 1.0
println(2.0f.pow(-2.0f)) // 0.25
println(4.0f.pow(0.5f)) // 2.0
println((-2.0f).pow(2.0f)) // 4.0

// special cases
println(Float.NaN.pow(42.0f)) // NaN
println(Float.NaN.pow(0.0f)) // 1.0
println(3.0f.pow(Float.NaN)) // NaN
println((-2.0f).pow(0.75f)) // NaN
println(1.0f.pow(Float.POSITIVE_INFINITY)) // NaN
println(1.0f.pow(Float.NEGATIVE_INFINITY)) // NaN
println(2.0f.pow(Float.POSITIVE_INFINITY)) // Infinity
println(2.0f.pow(Float.NEGATIVE_INFINITY)) // 0.0 
   //sampleEnd
}

actual inline fun Float.pow(n: Int): Float(source)

Raises this value to the integer power n.

See the other overload of pow for details.

Since Kotlin

1.2

Samples

import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   println(2.0f.pow(2)) // 4.0
println(3.0f.pow(1)) // 3.0
println(4.0f.pow(0)) // 1.0
println(2.0f.pow(-2)) // 0.25
println((-2.0f).pow(2)) // 4.0

// special cases
println(Float.NaN.pow(42)) // NaN
println(Float.NaN.pow(0)) // 1.0 
   //sampleEnd
}
actual external fun Double.pow(x: Double): Double(source)

Raises this value to the power x.

Special cases:

  • b.pow(0.0) is 1.0

  • b.pow(1.0) == b

  • b.pow(NaN) is NaN

  • NaN.pow(x) is NaN for x != 0.0

  • b.pow(Inf) is NaN for abs(b) == 1.0

  • b.pow(x) is NaN for b < 0 and x is finite and not an integer

Since Kotlin

1.3

Samples

import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   println(2.0.pow(2.0)) // 4.0
println(3.0.pow(1.0)) // 3.0
println(4.0.pow(0.0)) // 1.0
println(2.0.pow(-2.0)) // 0.25
println(4.0.pow(0.5)) // 2.0
println((-2.0).pow(2.0)) // 4.0

// special cases
println(Double.NaN.pow(42.0)) // NaN
println(Double.NaN.pow(0.0)) // 1.0
println(3.0.pow(Double.NaN)) // NaN
println((-2.0).pow(0.75)) // NaN
println(1.0.pow(Double.POSITIVE_INFINITY)) // NaN
println(1.0.pow(Double.NEGATIVE_INFINITY)) // NaN
println(2.0.pow(Double.POSITIVE_INFINITY)) // Infinity
println(2.0.pow(Double.NEGATIVE_INFINITY)) // 0.0 
   //sampleEnd
}

actual fun Double.pow(n: Int): Double(source)

Raises this value to the integer power n.

See the other overload of pow for details.

Since Kotlin

1.3

Samples

import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   println(2.0.pow(2)) // 4.0
println(3.0.pow(1)) // 3.0
println(4.0.pow(0)) // 1.0
println(2.0.pow(-2)) // 0.25
println((-2.0).pow(2)) // 4.0

// special cases
println(Double.NaN.pow(42)) // NaN
println(Double.NaN.pow(0)) // 1.0 
   //sampleEnd
}

actual external fun Float.pow(x: Float): Float(source)

Raises this value to the power x.

Special cases:

  • b.pow(0.0) is 1.0

  • b.pow(1.0) == b

  • b.pow(NaN) is NaN

  • NaN.pow(x) is NaN for x != 0.0

  • b.pow(Inf) is NaN for abs(b) == 1.0

  • b.pow(x) is NaN for b < 0 and x is finite and not an integer

Since Kotlin

1.3

Samples

import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   println(2.0f.pow(2.0f)) // 4.0
println(3.0f.pow(1.0f)) // 3.0
println(4.0f.pow(0.0f)) // 1.0
println(2.0f.pow(-2.0f)) // 0.25
println(4.0f.pow(0.5f)) // 2.0
println((-2.0f).pow(2.0f)) // 4.0

// special cases
println(Float.NaN.pow(42.0f)) // NaN
println(Float.NaN.pow(0.0f)) // 1.0
println(3.0f.pow(Float.NaN)) // NaN
println((-2.0f).pow(0.75f)) // NaN
println(1.0f.pow(Float.POSITIVE_INFINITY)) // NaN
println(1.0f.pow(Float.NEGATIVE_INFINITY)) // NaN
println(2.0f.pow(Float.POSITIVE_INFINITY)) // Infinity
println(2.0f.pow(Float.NEGATIVE_INFINITY)) // 0.0 
   //sampleEnd
}

actual fun Float.pow(n: Int): Float(source)

Raises this value to the integer power n.

See the other overload of pow for details.

Since Kotlin

1.3

Samples

import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   println(2.0f.pow(2)) // 4.0
println(3.0f.pow(1)) // 3.0
println(4.0f.pow(0)) // 1.0
println(2.0f.pow(-2)) // 0.25
println((-2.0f).pow(2)) // 4.0

// special cases
println(Float.NaN.pow(42)) // NaN
println(Float.NaN.pow(0)) // 1.0 
   //sampleEnd
}
actual fun Double.pow(x: Double): Double(source)

Raises this value to the power x.

Special cases:

  • b.pow(0.0) is 1.0

  • b.pow(1.0) == b

  • b.pow(NaN) is NaN

  • NaN.pow(x) is NaN for x != 0.0

  • b.pow(Inf) is NaN for abs(b) == 1.0

  • b.pow(x) is NaN for b < 0 and x is finite and not an integer

Since Kotlin

1.8

Samples

import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   println(2.0.pow(2.0)) // 4.0
println(3.0.pow(1.0)) // 3.0
println(4.0.pow(0.0)) // 1.0
println(2.0.pow(-2.0)) // 0.25
println(4.0.pow(0.5)) // 2.0
println((-2.0).pow(2.0)) // 4.0

// special cases
println(Double.NaN.pow(42.0)) // NaN
println(Double.NaN.pow(0.0)) // 1.0
println(3.0.pow(Double.NaN)) // NaN
println((-2.0).pow(0.75)) // NaN
println(1.0.pow(Double.POSITIVE_INFINITY)) // NaN
println(1.0.pow(Double.NEGATIVE_INFINITY)) // NaN
println(2.0.pow(Double.POSITIVE_INFINITY)) // Infinity
println(2.0.pow(Double.NEGATIVE_INFINITY)) // 0.0 
   //sampleEnd
}

actual fun Double.pow(n: Int): Double(source)

Raises this value to the integer power n.

See the other overload of pow for details.

Since Kotlin

1.8

Samples

import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   println(2.0.pow(2)) // 4.0
println(3.0.pow(1)) // 3.0
println(4.0.pow(0)) // 1.0
println(2.0.pow(-2)) // 0.25
println((-2.0).pow(2)) // 4.0

// special cases
println(Double.NaN.pow(42)) // NaN
println(Double.NaN.pow(0)) // 1.0 
   //sampleEnd
}

actual fun Float.pow(x: Float): Float(source)

Raises this value to the power x.

Special cases:

  • b.pow(0.0) is 1.0

  • b.pow(1.0) == b

  • b.pow(NaN) is NaN

  • NaN.pow(x) is NaN for x != 0.0

  • b.pow(Inf) is NaN for abs(b) == 1.0

  • b.pow(x) is NaN for b < 0 and x is finite and not an integer

Since Kotlin

1.8

Samples

import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   println(2.0f.pow(2.0f)) // 4.0
println(3.0f.pow(1.0f)) // 3.0
println(4.0f.pow(0.0f)) // 1.0
println(2.0f.pow(-2.0f)) // 0.25
println(4.0f.pow(0.5f)) // 2.0
println((-2.0f).pow(2.0f)) // 4.0

// special cases
println(Float.NaN.pow(42.0f)) // NaN
println(Float.NaN.pow(0.0f)) // 1.0
println(3.0f.pow(Float.NaN)) // NaN
println((-2.0f).pow(0.75f)) // NaN
println(1.0f.pow(Float.POSITIVE_INFINITY)) // NaN
println(1.0f.pow(Float.NEGATIVE_INFINITY)) // NaN
println(2.0f.pow(Float.POSITIVE_INFINITY)) // Infinity
println(2.0f.pow(Float.NEGATIVE_INFINITY)) // 0.0 
   //sampleEnd
}

actual fun Float.pow(n: Int): Float(source)

Raises this value to the integer power n.

See the other overload of pow for details.

Since Kotlin

1.8

Samples

import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   println(2.0f.pow(2)) // 4.0
println(3.0f.pow(1)) // 3.0
println(4.0f.pow(0)) // 1.0
println(2.0f.pow(-2)) // 0.25
println((-2.0f).pow(2)) // 4.0

// special cases
println(Float.NaN.pow(42)) // NaN
println(Float.NaN.pow(0)) // 1.0 
   //sampleEnd
}
actual fun Double.pow(x: Double): Double(source)

Raises this value to the power x.

Special cases:

  • b.pow(0.0) is 1.0

  • b.pow(1.0) == b

  • b.pow(NaN) is NaN

  • NaN.pow(x) is NaN for x != 0.0

  • b.pow(Inf) is NaN for abs(b) == 1.0

  • b.pow(x) is NaN for b < 0 and x is finite and not an integer

Since Kotlin

1.8

Samples

import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   println(2.0.pow(2.0)) // 4.0
println(3.0.pow(1.0)) // 3.0
println(4.0.pow(0.0)) // 1.0
println(2.0.pow(-2.0)) // 0.25
println(4.0.pow(0.5)) // 2.0
println((-2.0).pow(2.0)) // 4.0

// special cases
println(Double.NaN.pow(42.0)) // NaN
println(Double.NaN.pow(0.0)) // 1.0
println(3.0.pow(Double.NaN)) // NaN
println((-2.0).pow(0.75)) // NaN
println(1.0.pow(Double.POSITIVE_INFINITY)) // NaN
println(1.0.pow(Double.NEGATIVE_INFINITY)) // NaN
println(2.0.pow(Double.POSITIVE_INFINITY)) // Infinity
println(2.0.pow(Double.NEGATIVE_INFINITY)) // 0.0 
   //sampleEnd
}

actual fun Double.pow(n: Int): Double(source)

Raises this value to the integer power n.

See the other overload of pow for details.

Since Kotlin

1.8

Samples

import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   println(2.0.pow(2)) // 4.0
println(3.0.pow(1)) // 3.0
println(4.0.pow(0)) // 1.0
println(2.0.pow(-2)) // 0.25
println((-2.0).pow(2)) // 4.0

// special cases
println(Double.NaN.pow(42)) // NaN
println(Double.NaN.pow(0)) // 1.0 
   //sampleEnd
}

actual fun Float.pow(x: Float): Float(source)

Raises this value to the power x.

Special cases:

  • b.pow(0.0) is 1.0

  • b.pow(1.0) == b

  • b.pow(NaN) is NaN

  • NaN.pow(x) is NaN for x != 0.0

  • b.pow(Inf) is NaN for abs(b) == 1.0

  • b.pow(x) is NaN for b < 0 and x is finite and not an integer

Since Kotlin

1.8

Samples

import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   println(2.0f.pow(2.0f)) // 4.0
println(3.0f.pow(1.0f)) // 3.0
println(4.0f.pow(0.0f)) // 1.0
println(2.0f.pow(-2.0f)) // 0.25
println(4.0f.pow(0.5f)) // 2.0
println((-2.0f).pow(2.0f)) // 4.0

// special cases
println(Float.NaN.pow(42.0f)) // NaN
println(Float.NaN.pow(0.0f)) // 1.0
println(3.0f.pow(Float.NaN)) // NaN
println((-2.0f).pow(0.75f)) // NaN
println(1.0f.pow(Float.POSITIVE_INFINITY)) // NaN
println(1.0f.pow(Float.NEGATIVE_INFINITY)) // NaN
println(2.0f.pow(Float.POSITIVE_INFINITY)) // Infinity
println(2.0f.pow(Float.NEGATIVE_INFINITY)) // 0.0 
   //sampleEnd
}

actual fun Float.pow(n: Int): Float(source)

Raises this value to the integer power n.

See the other overload of pow for details.

Since Kotlin

1.8

Samples

import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   println(2.0f.pow(2)) // 4.0
println(3.0f.pow(1)) // 3.0
println(4.0f.pow(0)) // 1.0
println(2.0f.pow(-2)) // 0.25
println((-2.0f).pow(2)) // 4.0

// special cases
println(Float.NaN.pow(42)) // NaN
println(Float.NaN.pow(0)) // 1.0 
   //sampleEnd
}