cos
Computes the cosine of the angle x given in radians.
Special cases:
cos(NaN|+Inf|-Inf)isNaN
Since Kotlin
1.2Samples
import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
val epsilon = 1e-10
println(cos(0.0)) // 1.0
// Results may not be exact, so we're only checking that they are within epsilon from the expected value
// cos(π/2) = 0
println("cos(PI / 2).absoluteValue < epsilon is ${cos(PI / 2).absoluteValue < epsilon}") // true
println(cos(PI)) // -1.0
// special cases
println(cos(Double.NaN)) // NaN
println(cos(Double.POSITIVE_INFINITY)) // NaN
println(cos(Double.NEGATIVE_INFINITY)) // NaN
//sampleEnd
}Computes the cosine of the angle x given in radians.
Special cases:
cos(NaN|+Inf|-Inf)isNaN
Since Kotlin
1.2Samples
import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
val epsilon = 1e-6f
println(cos(0.0f)) // 1.0
// Results may not be exact, so we're only checking that they are within epsilon from the expected value
// cos(π/2) = 0
println("cos(PI.toFloat() / 2).absoluteValue < epsilon is ${cos(PI.toFloat() / 2).absoluteValue < epsilon}") // true
println(cos(PI.toFloat())) // -1.0
// special cases
println(cos(Float.NaN)) // NaN
println(cos(Float.POSITIVE_INFINITY)) // NaN
println(cos(Float.NEGATIVE_INFINITY)) // NaN
//sampleEnd
}Computes the cosine of the angle x given in radians.
Special cases:
cos(NaN|+Inf|-Inf)isNaN
Since Kotlin
1.2Samples
import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
val epsilon = 1e-10
println(cos(0.0)) // 1.0
// Results may not be exact, so we're only checking that they are within epsilon from the expected value
// cos(π/2) = 0
println("cos(PI / 2).absoluteValue < epsilon is ${cos(PI / 2).absoluteValue < epsilon}") // true
println(cos(PI)) // -1.0
// special cases
println(cos(Double.NaN)) // NaN
println(cos(Double.POSITIVE_INFINITY)) // NaN
println(cos(Double.NEGATIVE_INFINITY)) // NaN
//sampleEnd
}Computes the cosine of the angle x given in radians.
Special cases:
cos(NaN|+Inf|-Inf)isNaN
Since Kotlin
1.2Samples
import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
val epsilon = 1e-6f
println(cos(0.0f)) // 1.0
// Results may not be exact, so we're only checking that they are within epsilon from the expected value
// cos(π/2) = 0
println("cos(PI.toFloat() / 2).absoluteValue < epsilon is ${cos(PI.toFloat() / 2).absoluteValue < epsilon}") // true
println(cos(PI.toFloat())) // -1.0
// special cases
println(cos(Float.NaN)) // NaN
println(cos(Float.POSITIVE_INFINITY)) // NaN
println(cos(Float.NEGATIVE_INFINITY)) // NaN
//sampleEnd
}Computes the cosine of the angle x given in radians.
Special cases:
cos(NaN|+Inf|-Inf)isNaN
Since Kotlin
1.2Samples
import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
val epsilon = 1e-10
println(cos(0.0)) // 1.0
// Results may not be exact, so we're only checking that they are within epsilon from the expected value
// cos(π/2) = 0
println("cos(PI / 2).absoluteValue < epsilon is ${cos(PI / 2).absoluteValue < epsilon}") // true
println(cos(PI)) // -1.0
// special cases
println(cos(Double.NaN)) // NaN
println(cos(Double.POSITIVE_INFINITY)) // NaN
println(cos(Double.NEGATIVE_INFINITY)) // NaN
//sampleEnd
}Computes the cosine of the angle x given in radians.
Special cases:
cos(NaN|+Inf|-Inf)isNaN
Since Kotlin
1.2Samples
import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
val epsilon = 1e-6f
println(cos(0.0f)) // 1.0
// Results may not be exact, so we're only checking that they are within epsilon from the expected value
// cos(π/2) = 0
println("cos(PI.toFloat() / 2).absoluteValue < epsilon is ${cos(PI.toFloat() / 2).absoluteValue < epsilon}") // true
println(cos(PI.toFloat())) // -1.0
// special cases
println(cos(Float.NaN)) // NaN
println(cos(Float.POSITIVE_INFINITY)) // NaN
println(cos(Float.NEGATIVE_INFINITY)) // NaN
//sampleEnd
}Computes the cosine of the angle x given in radians.
Special cases:
cos(NaN|+Inf|-Inf)isNaN
Since Kotlin
1.3Samples
import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
val epsilon = 1e-10
println(cos(0.0)) // 1.0
// Results may not be exact, so we're only checking that they are within epsilon from the expected value
// cos(π/2) = 0
println("cos(PI / 2).absoluteValue < epsilon is ${cos(PI / 2).absoluteValue < epsilon}") // true
println(cos(PI)) // -1.0
// special cases
println(cos(Double.NaN)) // NaN
println(cos(Double.POSITIVE_INFINITY)) // NaN
println(cos(Double.NEGATIVE_INFINITY)) // NaN
//sampleEnd
}Computes the cosine of the angle x given in radians.
Special cases:
cos(NaN|+Inf|-Inf)isNaN
Since Kotlin
1.3Samples
import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
val epsilon = 1e-6f
println(cos(0.0f)) // 1.0
// Results may not be exact, so we're only checking that they are within epsilon from the expected value
// cos(π/2) = 0
println("cos(PI.toFloat() / 2).absoluteValue < epsilon is ${cos(PI.toFloat() / 2).absoluteValue < epsilon}") // true
println(cos(PI.toFloat())) // -1.0
// special cases
println(cos(Float.NaN)) // NaN
println(cos(Float.POSITIVE_INFINITY)) // NaN
println(cos(Float.NEGATIVE_INFINITY)) // NaN
//sampleEnd
}Computes the cosine of the angle x given in radians.
Special cases:
cos(NaN|+Inf|-Inf)isNaN
Since Kotlin
1.8Samples
import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
val epsilon = 1e-10
println(cos(0.0)) // 1.0
// Results may not be exact, so we're only checking that they are within epsilon from the expected value
// cos(π/2) = 0
println("cos(PI / 2).absoluteValue < epsilon is ${cos(PI / 2).absoluteValue < epsilon}") // true
println(cos(PI)) // -1.0
// special cases
println(cos(Double.NaN)) // NaN
println(cos(Double.POSITIVE_INFINITY)) // NaN
println(cos(Double.NEGATIVE_INFINITY)) // NaN
//sampleEnd
}Computes the cosine of the angle x given in radians.
Special cases:
cos(NaN|+Inf|-Inf)isNaN
Since Kotlin
1.8Samples
import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
val epsilon = 1e-6f
println(cos(0.0f)) // 1.0
// Results may not be exact, so we're only checking that they are within epsilon from the expected value
// cos(π/2) = 0
println("cos(PI.toFloat() / 2).absoluteValue < epsilon is ${cos(PI.toFloat() / 2).absoluteValue < epsilon}") // true
println(cos(PI.toFloat())) // -1.0
// special cases
println(cos(Float.NaN)) // NaN
println(cos(Float.POSITIVE_INFINITY)) // NaN
println(cos(Float.NEGATIVE_INFINITY)) // NaN
//sampleEnd
}Computes the cosine of the angle x given in radians.
Special cases:
cos(NaN|+Inf|-Inf)isNaN
Since Kotlin
1.8Samples
import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
val epsilon = 1e-10
println(cos(0.0)) // 1.0
// Results may not be exact, so we're only checking that they are within epsilon from the expected value
// cos(π/2) = 0
println("cos(PI / 2).absoluteValue < epsilon is ${cos(PI / 2).absoluteValue < epsilon}") // true
println(cos(PI)) // -1.0
// special cases
println(cos(Double.NaN)) // NaN
println(cos(Double.POSITIVE_INFINITY)) // NaN
println(cos(Double.NEGATIVE_INFINITY)) // NaN
//sampleEnd
}Computes the cosine of the angle x given in radians.
Special cases:
cos(NaN|+Inf|-Inf)isNaN
Since Kotlin
1.8Samples
import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
val epsilon = 1e-6f
println(cos(0.0f)) // 1.0
// Results may not be exact, so we're only checking that they are within epsilon from the expected value
// cos(π/2) = 0
println("cos(PI.toFloat() / 2).absoluteValue < epsilon is ${cos(PI.toFloat() / 2).absoluteValue < epsilon}") // true
println(cos(PI.toFloat())) // -1.0
// special cases
println(cos(Float.NaN)) // NaN
println(cos(Float.POSITIVE_INFINITY)) // NaN
println(cos(Float.NEGATIVE_INFINITY)) // NaN
//sampleEnd
}