hypot
Требования к платформе и версии: Common (1.2), Wasm-JS (1.8), Wasm-WASI (1.8)
expect fun hypot(x: Double, y: Double): Double
Вычисляет sqrt(x^2 + y^2) без промежуточного переполнения или потери значимости.
Особые случаи:
возвращает
+Inf, если любой из аргументов бесконеченвозвращает
NaN, если любой из аргументов равенNaN, а другой не является бесконечным
Примеры
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
Вычисляет sqrt(x^2 + y^2) без промежуточного переполнения или потери значимости.
Особые случаи:
возвращает
+Inf, если любой из аргументов бесконеченвозвращает
NaN, если любой из аргументов равенNaN, а другой не является бесконечным
Примеры
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
}
Требования к платформе и версии: JS (1.2), JVM (1.2)
actual inline fun hypot(x: Double, y: Double): Double
Вычисляет sqrt(x^2 + y^2) без промежуточного переполнения или потери значимости.
Особые случаи:
возвращает
+Inf, если любой из аргументов бесконеченвозвращает
NaN, если любой из аргументов равенNaN, а другой не является бесконечным
Примеры
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
Вычисляет sqrt(x^2 + y^2) без промежуточного переполнения или потери значимости.
Особые случаи:
возвращает
+Inf, если любой из аргументов бесконеченвозвращает
NaN, если любой из аргументов равенNaN, а другой не является бесконечным
Примеры
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
}
Требования к платформе и версии: Native (1.3)
actual external fun hypot(x: Double, y: Double): Double
Вычисляет sqrt(x^2 + y^2) без промежуточного переполнения или потери значимости.
Особые случаи:
возвращает
+Inf, если любой из аргументов бесконеченвозвращает
NaN, если любой из аргументов равенNaN, а другой не является бесконечным
Примеры
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
Вычисляет sqrt(x^2 + y^2) без промежуточного переполнения или потери значимости.
Особые случаи:
возвращает
+Inf, если любой из аргументов бесконеченвозвращает
NaN, если любой из аргументов равенNaN, а другой не является бесконечным
Примеры
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
}
© 2010–2026 JetBrains s.r.o. and Kotlin Programming Language contributors
Licensed under the Apache License, Version 2.0.
https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.math/hypot.html