cos

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

Computes the cosine of the angle x given in radians.

Special cases:

  • cos(NaN|+Inf|-Inf) is NaN

Since Kotlin

1.2

Samples

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
}

expect fun cos(x: Float): Float(source)

Computes the cosine of the angle x given in radians.

Special cases:

  • cos(NaN|+Inf|-Inf) is NaN

Since Kotlin

1.2

Samples

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

Computes the cosine of the angle x given in radians.

Special cases:

  • cos(NaN|+Inf|-Inf) is NaN

Since Kotlin

1.2

Samples

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
}

actual inline fun cos(x: Float): Float(source)

Computes the cosine of the angle x given in radians.

Special cases:

  • cos(NaN|+Inf|-Inf) is NaN

Since Kotlin

1.2

Samples

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

Computes the cosine of the angle x given in radians.

Special cases:

  • cos(NaN|+Inf|-Inf) is NaN

Since Kotlin

1.2

Samples

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
}

actual inline fun cos(x: Float): Float(source)

Computes the cosine of the angle x given in radians.

Special cases:

  • cos(NaN|+Inf|-Inf) is NaN

Since Kotlin

1.2

Samples

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

Computes the cosine of the angle x given in radians.

Special cases:

  • cos(NaN|+Inf|-Inf) is NaN

Since Kotlin

1.3

Samples

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
}

actual external fun cos(x: Float): Float(source)

Computes the cosine of the angle x given in radians.

Special cases:

  • cos(NaN|+Inf|-Inf) is NaN

Since Kotlin

1.3

Samples

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

Computes the cosine of the angle x given in radians.

Special cases:

  • cos(NaN|+Inf|-Inf) is NaN

Since Kotlin

1.8

Samples

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
}

actual fun cos(x: Float): Float(source)

Computes the cosine of the angle x given in radians.

Special cases:

  • cos(NaN|+Inf|-Inf) is NaN

Since Kotlin

1.8

Samples

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

Computes the cosine of the angle x given in radians.

Special cases:

  • cos(NaN|+Inf|-Inf) is NaN

Since Kotlin

1.8

Samples

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
}

actual fun cos(x: Float): Float(source)

Computes the cosine of the angle x given in radians.

Special cases:

  • cos(NaN|+Inf|-Inf) is NaN

Since Kotlin

1.8

Samples

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
}