sqrt

expect fun sqrt(x: Double): Double(source)

Computes the positive square root of the value x.

Special cases:

  • sqrt(NaN) is NaN

  • sqrt(-0.0) is -0.0

  • sqrt(x) is NaN when x < 0

Since Kotlin

1.2

Samples

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

fun main() { 
   //sampleStart 
   println(sqrt(9.0)) // 3.0
println(sqrt(5.76)) // 2.4
// special cases
println(sqrt(-0.0)) // -0.0
println(sqrt(-4.0)) // NaN
println(sqrt(Double.NaN)) // NaN
println(sqrt(Double.POSITIVE_INFINITY)) // Infinity 
   //sampleEnd
}

expect fun sqrt(x: Float): Float(source)

Computes the positive square root of the value x.

Special cases:

  • sqrt(NaN) is NaN

  • sqrt(-0.0) is -0.0

  • sqrt(x) is NaN when x < 0

Since Kotlin

1.2

Samples

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

fun main() { 
   //sampleStart 
   println(sqrt(9.0f)) // 3.0
println(sqrt(5.76f)) // 2.4

// special cases
println(sqrt(-0.0f)) // -0.0
println(sqrt(-4.0f)) // NaN
println(sqrt(Float.NaN)) // NaN
println(sqrt(Float.POSITIVE_INFINITY)) // Infinity 
   //sampleEnd
}
actual inline fun sqrt(x: Double): Double(source)

Computes the positive square root of the value x.

Special cases:

  • sqrt(NaN) is NaN

  • sqrt(-0.0) is -0.0

  • sqrt(x) is NaN when x < 0

Since Kotlin

1.2

Samples

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

fun main() { 
   //sampleStart 
   println(sqrt(9.0)) // 3.0
println(sqrt(5.76)) // 2.4
// special cases
println(sqrt(-0.0)) // -0.0
println(sqrt(-4.0)) // NaN
println(sqrt(Double.NaN)) // NaN
println(sqrt(Double.POSITIVE_INFINITY)) // Infinity 
   //sampleEnd
}

actual inline fun sqrt(x: Float): Float(source)

Computes the positive square root of the value x.

Special cases:

  • sqrt(NaN) is NaN

  • sqrt(-0.0) is -0.0

  • sqrt(x) is NaN when x < 0

Since Kotlin

1.2

Samples

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

fun main() { 
   //sampleStart 
   println(sqrt(9.0f)) // 3.0
println(sqrt(5.76f)) // 2.4

// special cases
println(sqrt(-0.0f)) // -0.0
println(sqrt(-4.0f)) // NaN
println(sqrt(Float.NaN)) // NaN
println(sqrt(Float.POSITIVE_INFINITY)) // Infinity 
   //sampleEnd
}
actual inline fun sqrt(x: Double): Double(source)

Computes the positive square root of the value x.

Special cases:

  • sqrt(NaN) is NaN

  • sqrt(-0.0) is -0.0

  • sqrt(x) is NaN when x < 0

Since Kotlin

1.2

Samples

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

fun main() { 
   //sampleStart 
   println(sqrt(9.0)) // 3.0
println(sqrt(5.76)) // 2.4
// special cases
println(sqrt(-0.0)) // -0.0
println(sqrt(-4.0)) // NaN
println(sqrt(Double.NaN)) // NaN
println(sqrt(Double.POSITIVE_INFINITY)) // Infinity 
   //sampleEnd
}

actual inline fun sqrt(x: Float): Float(source)

Computes the positive square root of the value x.

Special cases:

  • sqrt(NaN) is NaN

  • sqrt(-0.0) is -0.0

  • sqrt(x) is NaN when x < 0

Since Kotlin

1.2

Samples

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

fun main() { 
   //sampleStart 
   println(sqrt(9.0f)) // 3.0
println(sqrt(5.76f)) // 2.4

// special cases
println(sqrt(-0.0f)) // -0.0
println(sqrt(-4.0f)) // NaN
println(sqrt(Float.NaN)) // NaN
println(sqrt(Float.POSITIVE_INFINITY)) // Infinity 
   //sampleEnd
}
actual external fun sqrt(x: Double): Double(source)

Computes the positive square root of the value x.

Special cases:

  • sqrt(NaN) is NaN

  • sqrt(-0.0) is -0.0

  • sqrt(x) is NaN when x < 0

Since Kotlin

1.3

Samples

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

fun main() { 
   //sampleStart 
   println(sqrt(9.0)) // 3.0
println(sqrt(5.76)) // 2.4
// special cases
println(sqrt(-0.0)) // -0.0
println(sqrt(-4.0)) // NaN
println(sqrt(Double.NaN)) // NaN
println(sqrt(Double.POSITIVE_INFINITY)) // Infinity 
   //sampleEnd
}

actual external fun sqrt(x: Float): Float(source)

Computes the positive square root of the value x.

Special cases:

  • sqrt(NaN) is NaN

  • sqrt(-0.0) is -0.0

  • sqrt(x) is NaN when x < 0

Since Kotlin

1.3

Samples

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

fun main() { 
   //sampleStart 
   println(sqrt(9.0f)) // 3.0
println(sqrt(5.76f)) // 2.4

// special cases
println(sqrt(-0.0f)) // -0.0
println(sqrt(-4.0f)) // NaN
println(sqrt(Float.NaN)) // NaN
println(sqrt(Float.POSITIVE_INFINITY)) // Infinity 
   //sampleEnd
}
actual fun sqrt(x: Double): Double(source)

Computes the positive square root of the value x.

Special cases:

  • sqrt(NaN) is NaN

  • sqrt(-0.0) is -0.0

  • sqrt(x) is NaN when x < 0

Since Kotlin

1.8

Samples

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

fun main() { 
   //sampleStart 
   println(sqrt(9.0)) // 3.0
println(sqrt(5.76)) // 2.4
// special cases
println(sqrt(-0.0)) // -0.0
println(sqrt(-4.0)) // NaN
println(sqrt(Double.NaN)) // NaN
println(sqrt(Double.POSITIVE_INFINITY)) // Infinity 
   //sampleEnd
}

actual fun sqrt(x: Float): Float(source)

Computes the positive square root of the value x.

Special cases:

  • sqrt(NaN) is NaN

  • sqrt(-0.0) is -0.0

  • sqrt(x) is NaN when x < 0

Since Kotlin

1.8

Samples

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

fun main() { 
   //sampleStart 
   println(sqrt(9.0f)) // 3.0
println(sqrt(5.76f)) // 2.4

// special cases
println(sqrt(-0.0f)) // -0.0
println(sqrt(-4.0f)) // NaN
println(sqrt(Float.NaN)) // NaN
println(sqrt(Float.POSITIVE_INFINITY)) // Infinity 
   //sampleEnd
}
actual fun sqrt(x: Double): Double(source)

Computes the positive square root of the value x.

Special cases:

  • sqrt(NaN) is NaN

  • sqrt(-0.0) is -0.0

  • sqrt(x) is NaN when x < 0

Since Kotlin

1.8

Samples

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

fun main() { 
   //sampleStart 
   println(sqrt(9.0)) // 3.0
println(sqrt(5.76)) // 2.4
// special cases
println(sqrt(-0.0)) // -0.0
println(sqrt(-4.0)) // NaN
println(sqrt(Double.NaN)) // NaN
println(sqrt(Double.POSITIVE_INFINITY)) // Infinity 
   //sampleEnd
}

actual fun sqrt(x: Float): Float(source)

Computes the positive square root of the value x.

Special cases:

  • sqrt(NaN) is NaN

  • sqrt(-0.0) is -0.0

  • sqrt(x) is NaN when x < 0

Since Kotlin

1.8

Samples

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

fun main() { 
   //sampleStart 
   println(sqrt(9.0f)) // 3.0
println(sqrt(5.76f)) // 2.4

// special cases
println(sqrt(-0.0f)) // -0.0
println(sqrt(-4.0f)) // NaN
println(sqrt(Float.NaN)) // NaN
println(sqrt(Float.POSITIVE_INFINITY)) // Infinity 
   //sampleEnd
}