acos
Требования к платформе и версии: Common (1.2), Wasm-JS (1.8), Wasm-WASI (1.8)
expect fun acos(x: Double): Double
Вычисляет арккосинус значения x; возвращаемое значение — угол в диапазоне от 0.0 до PI радиан.
Особые случаи:
acos(x)равноNaN, когдаabs(x) > 1или x равноNaN
Примеры
import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
val epsilon = 1e-10
println(acos(1.0)) // 0.0
// Results may not be exact, so we're only checking that they are within epsilon from the expected value
// acos(0.0) = π/2
println("(acos(0.0) - PI / 2).absoluteValue < epsilon is ${(acos(0.0) - PI / 2).absoluteValue < epsilon}") // true
// acos(-1.0) = π
println("(acos(-1.0) - PI).absoluteValue < epsilon is ${(acos(-1.0) - PI).absoluteValue < epsilon}") // true
// acos(cos(x)) = x
println("(acos(cos(0.123)) - 0.123).absoluteValue < epsilon is ${(acos(cos(0.123)) - 0.123).absoluteValue < epsilon}") // true
// special cases
println(acos(Double.NaN)) // NaN
println(acos(1.1)) // NaN
println(acos(-2.0)) // NaN
//sampleEnd
}
expect fun acos(x: Float): Float
Вычисляет арккосинус значения x; возвращаемое значение — угол в диапазоне от 0.0 до PI радиан.
Особые случаи:
acos(x)равноNaN, когдаabs(x) > 1или x равноNaN
Примеры
import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
val epsilon = 1e-6f
println(acos(1.0f)) // 0.0
// Results may not be exact, so we're only checking that they are within epsilon from the expected value
// acos(0.0) = π/2
println("(acos(0.0f) - PI.toFloat() / 2).absoluteValue < epsilon is ${(acos(0.0f) - PI.toFloat() / 2).absoluteValue < epsilon}") // true
// acos(-1.0) = π
println("(acos(-1.0f) - PI.toFloat()).absoluteValue < epsilon is ${(acos(-1.0f) - PI.toFloat()).absoluteValue < epsilon}") // true
// acos(cos(x)) = x
println("(acos(cos(0.25f)) - 0.25f).absoluteValue < epsilon is ${(acos(cos(0.25f)) - 0.25f).absoluteValue < epsilon}") // true
// special cases
println(acos(Float.NaN)) // NaN
println(acos(1.1f)) // NaN
println(acos(-2.0f)) // NaN
//sampleEnd
}
Требования к платформе и версии: JS (1.2), JVM (1.2)
actual inline fun acos(x: Double): Double
Вычисляет арккосинус значения x; возвращаемое значение — угол в диапазоне от 0.0 до PI радиан.
Особые случаи:
acos(x)равноNaN, когдаabs(x) > 1или x равноNaN
Примеры
import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
val epsilon = 1e-10
println(acos(1.0)) // 0.0
// Results may not be exact, so we're only checking that they are within epsilon from the expected value
// acos(0.0) = π/2
println("(acos(0.0) - PI / 2).absoluteValue < epsilon is ${(acos(0.0) - PI / 2).absoluteValue < epsilon}") // true
// acos(-1.0) = π
println("(acos(-1.0) - PI).absoluteValue < epsilon is ${(acos(-1.0) - PI).absoluteValue < epsilon}") // true
// acos(cos(x)) = x
println("(acos(cos(0.123)) - 0.123).absoluteValue < epsilon is ${(acos(cos(0.123)) - 0.123).absoluteValue < epsilon}") // true
// special cases
println(acos(Double.NaN)) // NaN
println(acos(1.1)) // NaN
println(acos(-2.0)) // NaN
//sampleEnd
}
actual inline fun acos(x: Float): Float
Вычисляет арккосинус значения x; возвращаемое значение — угол в диапазоне от 0.0 до PI радиан.
Особые случаи:
acos(x)равноNaN, когдаabs(x) > 1или x равноNaN
Примеры
import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
val epsilon = 1e-6f
println(acos(1.0f)) // 0.0
// Results may not be exact, so we're only checking that they are within epsilon from the expected value
// acos(0.0) = π/2
println("(acos(0.0f) - PI.toFloat() / 2).absoluteValue < epsilon is ${(acos(0.0f) - PI.toFloat() / 2).absoluteValue < epsilon}") // true
// acos(-1.0) = π
println("(acos(-1.0f) - PI.toFloat()).absoluteValue < epsilon is ${(acos(-1.0f) - PI.toFloat()).absoluteValue < epsilon}") // true
// acos(cos(x)) = x
println("(acos(cos(0.25f)) - 0.25f).absoluteValue < epsilon is ${(acos(cos(0.25f)) - 0.25f).absoluteValue < epsilon}") // true
// special cases
println(acos(Float.NaN)) // NaN
println(acos(1.1f)) // NaN
println(acos(-2.0f)) // NaN
//sampleEnd
}
Требования к платформе и версии: Native (1.3)
actual external fun acos(x: Double): Double
Вычисляет арккосинус значения x; возвращаемое значение — угол в диапазоне от 0.0 до PI радиан.
Особые случаи:
acos(x)равноNaN, когдаabs(x) > 1или x равноNaN
Примеры
import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
val epsilon = 1e-10
println(acos(1.0)) // 0.0
// Results may not be exact, so we're only checking that they are within epsilon from the expected value
// acos(0.0) = π/2
println("(acos(0.0) - PI / 2).absoluteValue < epsilon is ${(acos(0.0) - PI / 2).absoluteValue < epsilon}") // true
// acos(-1.0) = π
println("(acos(-1.0) - PI).absoluteValue < epsilon is ${(acos(-1.0) - PI).absoluteValue < epsilon}") // true
// acos(cos(x)) = x
println("(acos(cos(0.123)) - 0.123).absoluteValue < epsilon is ${(acos(cos(0.123)) - 0.123).absoluteValue < epsilon}") // true
// special cases
println(acos(Double.NaN)) // NaN
println(acos(1.1)) // NaN
println(acos(-2.0)) // NaN
//sampleEnd
}
actual external fun acos(x: Float): Float
Вычисляет арккосинус значения x; возвращаемое значение — угол в диапазоне от 0.0 до PI радиан.
Особые случаи:
acos(x)равноNaN, когдаabs(x) > 1или x равноNaN
Примеры
import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
val epsilon = 1e-6f
println(acos(1.0f)) // 0.0
// Results may not be exact, so we're only checking that they are within epsilon from the expected value
// acos(0.0) = π/2
println("(acos(0.0f) - PI.toFloat() / 2).absoluteValue < epsilon is ${(acos(0.0f) - PI.toFloat() / 2).absoluteValue < epsilon}") // true
// acos(-1.0) = π
println("(acos(-1.0f) - PI.toFloat()).absoluteValue < epsilon is ${(acos(-1.0f) - PI.toFloat()).absoluteValue < epsilon}") // true
// acos(cos(x)) = x
println("(acos(cos(0.25f)) - 0.25f).absoluteValue < epsilon is ${(acos(cos(0.25f)) - 0.25f).absoluteValue < epsilon}") // true
// special cases
println(acos(Float.NaN)) // NaN
println(acos(1.1f)) // NaN
println(acos(-2.0f)) // NaN
//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/acos.html