Published Nov 13, 2023
Contribute to Docs

The math.cos() method in Kotlin’s math class is used to calculate the cosine of an angle in radians.


val cosineValue = cos(angle)
  • angle: The angle in radians for which to calculate the cosine.
  • The math.cos() method returns a value of type Double representing the cosine of the input angle.


The example below demonstrates how to use math.cos() method to calculate the cosine of an angle:

import kotlin.math.*
fun main() {
val angle = PI / 3.0 // 60 degrees in radians
val cosineValue = cos(angle)
println("The cosine of $angle radians is $cosineValue.")

This results in the following output:

The cosine of 1.0471975511965979 radians is 0.5000000000000001.

All contributors

Looking to contribute?

Learn Kotlin on Codecademy