Kotlin 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 typeDoublerepresenting 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
- Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
- Includes 6 Courses
- With Professional Certification
- Beginner Friendly.75 hours
- Learn Kotlin, the expressive, open-source programming language developed by JetBrains.
- Beginner Friendly.9 hours