tan()

data2294409510's avatar
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 as Double or Float as a parameter.
  • The function returns a Double value, 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

All contributors

Contribute to Docs

Learn Kotlin on Codecademy