hypot

expect fun hypot(x: Double, y: Double): Double(source)

Computes sqrt(x^2 + y^2) without intermediate overflow or underflow.

Special cases:

  • returns +Inf if any of arguments is infinite

  • returns NaN if any of arguments is NaN and the other is not infinite

Since Kotlin

1.2

Samples

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

fun main() { 
   //sampleStart 
   // sqrt(6 * 6 + 8 * 8) = sqrt(36 + 64) = sqrt(100) = 10
println(hypot(6.0, 8.0)) // 10.0

// special cases
println(hypot(Double.NaN, 2.0)) // NaN
println(hypot(1.0, Double.NaN)) // NaN
println(hypot(Double.POSITIVE_INFINITY, 2.0)) // Infinity
println(hypot(1.0, Double.NEGATIVE_INFINITY)) // Infinity 
   //sampleEnd
}

expect fun hypot(x: Float, y: Float): Float(source)

Computes sqrt(x^2 + y^2) without intermediate overflow or underflow.

Special cases:

  • returns +Inf if any of arguments is infinite

  • returns NaN if any of arguments is NaN and the other is not infinite

Since Kotlin

1.2

Samples

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

fun main() { 
   //sampleStart 
   // sqrt(6 * 6 + 8 * 8) = sqrt(36 + 64) = sqrt(100) = 10
println(hypot(6.0f, 8.0f)) // 10.0

// special cases
println(hypot(Float.NaN, 2.0f)) // NaN
println(hypot(1.0f, Float.NaN)) // NaN
println(hypot(Float.POSITIVE_INFINITY, 2.0f)) // Infinity
println(hypot(1.0f, Float.NEGATIVE_INFINITY)) // Infinity 
   //sampleEnd
}
actual inline fun hypot(x: Double, y: Double): Double(source)

Computes sqrt(x^2 + y^2) without intermediate overflow or underflow.

Special cases:

  • returns +Inf if any of arguments is infinite

  • returns NaN if any of arguments is NaN and the other is not infinite

Since Kotlin

1.2

Samples

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

fun main() { 
   //sampleStart 
   // sqrt(6 * 6 + 8 * 8) = sqrt(36 + 64) = sqrt(100) = 10
println(hypot(6.0, 8.0)) // 10.0

// special cases
println(hypot(Double.NaN, 2.0)) // NaN
println(hypot(1.0, Double.NaN)) // NaN
println(hypot(Double.POSITIVE_INFINITY, 2.0)) // Infinity
println(hypot(1.0, Double.NEGATIVE_INFINITY)) // Infinity 
   //sampleEnd
}

actual inline fun hypot(x: Float, y: Float): Float(source)

Computes sqrt(x^2 + y^2) without intermediate overflow or underflow.

Special cases:

  • returns +Inf if any of arguments is infinite

  • returns NaN if any of arguments is NaN and the other is not infinite

Since Kotlin

1.2

Samples

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

fun main() { 
   //sampleStart 
   // sqrt(6 * 6 + 8 * 8) = sqrt(36 + 64) = sqrt(100) = 10
println(hypot(6.0f, 8.0f)) // 10.0

// special cases
println(hypot(Float.NaN, 2.0f)) // NaN
println(hypot(1.0f, Float.NaN)) // NaN
println(hypot(Float.POSITIVE_INFINITY, 2.0f)) // Infinity
println(hypot(1.0f, Float.NEGATIVE_INFINITY)) // Infinity 
   //sampleEnd
}
actual inline fun hypot(x: Double, y: Double): Double(source)

Computes sqrt(x^2 + y^2) without intermediate overflow or underflow.

Special cases:

  • returns +Inf if any of arguments is infinite

  • returns NaN if any of arguments is NaN and the other is not infinite

Since Kotlin

1.2

Samples

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

fun main() { 
   //sampleStart 
   // sqrt(6 * 6 + 8 * 8) = sqrt(36 + 64) = sqrt(100) = 10
println(hypot(6.0, 8.0)) // 10.0

// special cases
println(hypot(Double.NaN, 2.0)) // NaN
println(hypot(1.0, Double.NaN)) // NaN
println(hypot(Double.POSITIVE_INFINITY, 2.0)) // Infinity
println(hypot(1.0, Double.NEGATIVE_INFINITY)) // Infinity 
   //sampleEnd
}

actual inline fun hypot(x: Float, y: Float): Float(source)

Computes sqrt(x^2 + y^2) without intermediate overflow or underflow.

Special cases:

  • returns +Inf if any of arguments is infinite

  • returns NaN if any of arguments is NaN and the other is not infinite

Since Kotlin

1.2

Samples

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

fun main() { 
   //sampleStart 
   // sqrt(6 * 6 + 8 * 8) = sqrt(36 + 64) = sqrt(100) = 10
println(hypot(6.0f, 8.0f)) // 10.0

// special cases
println(hypot(Float.NaN, 2.0f)) // NaN
println(hypot(1.0f, Float.NaN)) // NaN
println(hypot(Float.POSITIVE_INFINITY, 2.0f)) // Infinity
println(hypot(1.0f, Float.NEGATIVE_INFINITY)) // Infinity 
   //sampleEnd
}
actual external fun hypot(x: Double, y: Double): Double(source)

Computes sqrt(x^2 + y^2) without intermediate overflow or underflow.

Special cases:

  • returns +Inf if any of arguments is infinite

  • returns NaN if any of arguments is NaN and the other is not infinite

Since Kotlin

1.3

Samples

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

fun main() { 
   //sampleStart 
   // sqrt(6 * 6 + 8 * 8) = sqrt(36 + 64) = sqrt(100) = 10
println(hypot(6.0, 8.0)) // 10.0

// special cases
println(hypot(Double.NaN, 2.0)) // NaN
println(hypot(1.0, Double.NaN)) // NaN
println(hypot(Double.POSITIVE_INFINITY, 2.0)) // Infinity
println(hypot(1.0, Double.NEGATIVE_INFINITY)) // Infinity 
   //sampleEnd
}

actual external fun hypot(x: Float, y: Float): Float(source)

Computes sqrt(x^2 + y^2) without intermediate overflow or underflow.

Special cases:

  • returns +Inf if any of arguments is infinite

  • returns NaN if any of arguments is NaN and the other is not infinite

Since Kotlin

1.3

Samples

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

fun main() { 
   //sampleStart 
   // sqrt(6 * 6 + 8 * 8) = sqrt(36 + 64) = sqrt(100) = 10
println(hypot(6.0f, 8.0f)) // 10.0

// special cases
println(hypot(Float.NaN, 2.0f)) // NaN
println(hypot(1.0f, Float.NaN)) // NaN
println(hypot(Float.POSITIVE_INFINITY, 2.0f)) // Infinity
println(hypot(1.0f, Float.NEGATIVE_INFINITY)) // Infinity 
   //sampleEnd
}
actual fun hypot(x: Double, y: Double): Double(source)

Computes sqrt(x^2 + y^2) without intermediate overflow or underflow.

Special cases:

  • returns +Inf if any of arguments is infinite

  • returns NaN if any of arguments is NaN and the other is not infinite

Since Kotlin

1.8

Samples

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

fun main() { 
   //sampleStart 
   // sqrt(6 * 6 + 8 * 8) = sqrt(36 + 64) = sqrt(100) = 10
println(hypot(6.0, 8.0)) // 10.0

// special cases
println(hypot(Double.NaN, 2.0)) // NaN
println(hypot(1.0, Double.NaN)) // NaN
println(hypot(Double.POSITIVE_INFINITY, 2.0)) // Infinity
println(hypot(1.0, Double.NEGATIVE_INFINITY)) // Infinity 
   //sampleEnd
}

actual fun hypot(x: Float, y: Float): Float(source)

Computes sqrt(x^2 + y^2) without intermediate overflow or underflow.

Special cases:

  • returns +Inf if any of arguments is infinite

  • returns NaN if any of arguments is NaN and the other is not infinite

Since Kotlin

1.8

Samples

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

fun main() { 
   //sampleStart 
   // sqrt(6 * 6 + 8 * 8) = sqrt(36 + 64) = sqrt(100) = 10
println(hypot(6.0f, 8.0f)) // 10.0

// special cases
println(hypot(Float.NaN, 2.0f)) // NaN
println(hypot(1.0f, Float.NaN)) // NaN
println(hypot(Float.POSITIVE_INFINITY, 2.0f)) // Infinity
println(hypot(1.0f, Float.NEGATIVE_INFINITY)) // Infinity 
   //sampleEnd
}
actual fun hypot(x: Double, y: Double): Double(source)

Computes sqrt(x^2 + y^2) without intermediate overflow or underflow.

Special cases:

  • returns +Inf if any of arguments is infinite

  • returns NaN if any of arguments is NaN and the other is not infinite

Since Kotlin

1.8

Samples

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

fun main() { 
   //sampleStart 
   // sqrt(6 * 6 + 8 * 8) = sqrt(36 + 64) = sqrt(100) = 10
println(hypot(6.0, 8.0)) // 10.0

// special cases
println(hypot(Double.NaN, 2.0)) // NaN
println(hypot(1.0, Double.NaN)) // NaN
println(hypot(Double.POSITIVE_INFINITY, 2.0)) // Infinity
println(hypot(1.0, Double.NEGATIVE_INFINITY)) // Infinity 
   //sampleEnd
}

actual fun hypot(x: Float, y: Float): Float(source)

Computes sqrt(x^2 + y^2) without intermediate overflow or underflow.

Special cases:

  • returns +Inf if any of arguments is infinite

  • returns NaN if any of arguments is NaN and the other is not infinite

Since Kotlin

1.8

Samples

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

fun main() { 
   //sampleStart 
   // sqrt(6 * 6 + 8 * 8) = sqrt(36 + 64) = sqrt(100) = 10
println(hypot(6.0f, 8.0f)) // 10.0

// special cases
println(hypot(Float.NaN, 2.0f)) // NaN
println(hypot(1.0f, Float.NaN)) // NaN
println(hypot(Float.POSITIVE_INFINITY, 2.0f)) // Infinity
println(hypot(1.0f, Float.NEGATIVE_INFINITY)) // Infinity 
   //sampleEnd
}