Anonymous contributor's avatar
Anonymous contributor
Anonymous contributor's avatar
Anonymous contributor
Published Dec 18, 2022
Contribute to Docs

The Math.tanh() method returns the hyperbolic sine of a double-type value.


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 num is NaN, then the result is NaN.
  • If num is zero, then the result is a zero with the same sign as the argument.
  • If num is positive infinity, then the result is +1.0.
  • If num is negative infinity, then the result is -1.0.

The computed result will be within 2.5 units of least precision (ulps) of the exact result.


The following example demonstrates the application of the .tanh() method:

// Check.java
public class Check {
public static void main(String args[]) {
// Value of num in degrees
double num = 45.0;
// Convert into radians
num = Math.toRadians(num);
// Compute and print hyperbolic tangent

This results in the following output:


All contributors

Looking to contribute?

Learn Java on Codecademy