cos()
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.
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.
Contribute to Docs
- 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.
Learn Kotlin on Codecademy
- Career path
Computer Science
Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!Includes 6 CoursesWith Professional CertificationBeginner Friendly75 hours - Free course
Learn Kotlin
Learn Kotlin, the expressive, open-source programming language developed by JetBrains.Beginner Friendly9 hours