Java Math - tanh() Method
The java.lang.Math.tanh() method returns hyperbolic tangent of a value. The hyperbolic tangent of x is defined as:
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 x)
Parameters
x |
Specify the value whose hyperbolic tangent is to be returned. |
Return Value
Returns the hyperbolic tangent of x.
Exception
NA.
Example:
In the example below, tanh() method is used to find out the hyperbolic tangent of a value.
import java.lang.*; 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.lang - Math