Java .tanh()
Published Dec 18, 2022Updated Jun 10, 2025
Contribute to Docs
The Math.tanh() method returns the hyperbolic sine of a double-type value.
Syntax
Math.tanh(double num)
The .tanh() method takes a single num parameter that represents the angle (given in radians) whose hyperbolic tangent is to be determined. The return type of the .tanh() method is a double.
Some special cases for the .tanh() method include the following:
- If
numisNaN, then the result isNaN. - If
numiszero, then the result is azerowith the same sign as the argument. - If
numispositiveinfinity, then the result is+1.0. - If
numisnegativeinfinity, then the result is-1.0.
The computed result will be within 2.5 units of least precision (ulps) of the exact result.
Example
The following example demonstrates the application of the .tanh() method:
// Check.javapublic class Check {public static void main(String args[]) {// Value of num in degreesdouble num = 45.0;// Convert into radiansnum = Math.toRadians(num);// Compute and print hyperbolic tangentSystem.out.println(Math.tanh(num));}}
This results in the following output:
0.6557942026326724
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 Java 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 to code in Java — a robust programming language used to create software, web and mobile apps, and more.
- Beginner Friendly.17 hours