Java .tanh()
Published Dec 18, 2022Updated Jun 10, 2025
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