cos()
The math.cos()
method in Kotlin’s math
class is used to calculate the cosine of an angle in radians.
Syntax
val cosineValue = cos(angle)
angle
: The angle in radians for which to calculate thecosine
.- The
math.cos()
method returns a value of typeDouble
representing the cosine of the input angle.
Example
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 radiansval 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.
Looking to contribute?
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.