Java Tutorial Java Advanced Java References

Java Math - tanh() Method



The Java tanh() method returns hyperbolic tangent of a value. The hyperbolic tangent of x is defined as:

tanh

where e is an Euler's number.

In special cases it returns the following:

  • If the argument is NaN, then the result is NaN.
  • If the argument is zero, then the result is a zero with the same sign as the argument.
  • If the argument is positive infinity, then the result is +1.0.
  • If the argument is negative infinity, then the result is -1.0.

Syntax

public static double tanh(double arg)

Parameters

arg Specify the value.

Return Value

Returns the hyperbolic tangent of a value.

Exception

NA.

Example:

In the example below, tanh() method is used to find out the hyperbolic tangent of a value.

public class MyClass {
 public static void main(String[] args) {
  System.out.println(Math.tanh(0));   
  System.out.println(Math.tanh(2));
  System.out.println(Math.tanh(4));     
 }
}

The output of the above code will be:

0.0
0.9640275800758169
0.999329299739067

❮ Java Math Methods