acos

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

Computes the arc cosine of the value x; the returned value is an angle in the range from 0.0 to PI radians.

Special cases:

  • acos(x) is NaN, when abs(x) > 1 or x is NaN

Since Kotlin

1.2

Samples

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(source)

Computes the arc cosine of the value x; the returned value is an angle in the range from 0.0 to PI radians.

Special cases:

  • acos(x) is NaN, when abs(x) > 1 or x is NaN

Since Kotlin

1.2

Samples

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
}
actual inline fun acos(x: Double): Double(source)

Computes the arc cosine of the value x; the returned value is an angle in the range from 0.0 to PI radians.

Special cases:

  • acos(x) is NaN, when abs(x) > 1 or x is NaN

Since Kotlin

1.2

Samples

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(source)

Computes the arc cosine of the value x; the returned value is an angle in the range from 0.0 to PI radians.

Special cases:

  • acos(x) is NaN, when abs(x) > 1 or x is NaN

Since Kotlin

1.2

Samples

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
}
actual inline fun acos(x: Double): Double(source)

Computes the arc cosine of the value x; the returned value is an angle in the range from 0.0 to PI radians.

Special cases:

  • acos(x) is NaN, when abs(x) > 1 or x is NaN

Since Kotlin

1.2

Samples

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(source)

Computes the arc cosine of the value x; the returned value is an angle in the range from 0.0 to PI radians.

Special cases:

  • acos(x) is NaN, when abs(x) > 1 or x is NaN

Since Kotlin

1.2

Samples

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
}
actual external fun acos(x: Double): Double(source)

Computes the arc cosine of the value x; the returned value is an angle in the range from 0.0 to PI radians.

Special cases:

  • acos(x) is NaN, when abs(x) > 1 or x is NaN

Since Kotlin

1.3

Samples

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(source)

Computes the arc cosine of the value x; the returned value is an angle in the range from 0.0 to PI radians.

Special cases:

  • acos(x) is NaN, when abs(x) > 1 or x is NaN

Since Kotlin

1.3

Samples

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
}
actual fun acos(x: Double): Double(source)

Computes the arc cosine of the value x; the returned value is an angle in the range from 0.0 to PI radians.

Special cases:

  • acos(x) is NaN, when abs(x) > 1 or x is NaN

Since Kotlin

1.8

Samples

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 fun acos(x: Float): Float(source)

Computes the arc cosine of the value x; the returned value is an angle in the range from 0.0 to PI radians.

Special cases:

  • acos(x) is NaN, when abs(x) > 1 or x is NaN

Since Kotlin

1.8

Samples

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
}
actual fun acos(x: Double): Double(source)

Computes the arc cosine of the value x; the returned value is an angle in the range from 0.0 to PI radians.

Special cases:

  • acos(x) is NaN, when abs(x) > 1 or x is NaN

Since Kotlin

1.8

Samples

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 fun acos(x: Float): Float(source)

Computes the arc cosine of the value x; the returned value is an angle in the range from 0.0 to PI radians.

Special cases:

  • acos(x) is NaN, when abs(x) > 1 or x is NaN

Since Kotlin

1.8

Samples

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
}