Kotlin .tanh()
Published Oct 31, 2023
The .tanh() method in Kotlin’s math class computes the hyperbolic tangent of an angle given in radians. The method takes the angle as its one and only parameter and returns the computed value as Double or Float type.
Syntax
tanh(x)
-x: This parameter takes a value of an angle in Double or Float type.
Example
The following code is basic implementation of math.tanh().
import kotlin.math.*fun main() {val x = 1.0val y = tanh(x)// print resultsprintln(y)}
This example will output:
0.7615941559557649
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