Kotlin tan()
Published Oct 31, 2023
Contribute to Docs
The tan() function is used to calculate the tangent of an angle. The tangent of an angle is the ratio of the length of the opposite side to the length of the adjacent side in a right triangle.
Syntax
tan(x)
- The function accepts one mandatory parameter
x. They all take an angle in radians asDoubleorFloatas a parameter. - The function returns a
Doublevalue, which is the tangent of the angle.
Example
The example below demonstrates how to use the tan() function in Kotlin to calculate the tangent of the angle 45 degrees in radians.
import kotlin.math.*fun main() {val angleInRadians = Math.toRadians(45.0)val tangent = tan(angleInRadians)println(tangent)}
The output will be:
1.0
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