Java Math.tanh() method returns hyperbolic tangent of the given value. This method accepts double type value as an argument and returns the hyperbolic tangent of this value as a result. Hyperbolic tangent of a value x is defined as (ex – e-x)/(ex + e-x), where e is the Euler’s number whose value is 2.718281828459045.
public class JavaExample
{
public static void main(String[] args)
{
double x = 30;
System.out.println(Math.tanh(x));
}
}
Output:
1.0
Syntax of Math.tanh() method
Math.tanh(90); //returns 1.0
tanh() Description
public static double tanh(double x): Returns the hyperbolic tangent of the given value (argument) x.
tanh() Parameters
- x: A double value whose hyperbolic tangent is to be determined.
tanh() Return Value
- Returns hyperbolic tangent of argument
x. - If the argument
xis NaN (Not a number), then it returns NaN. - If the argument
xis zero, then it returns the zero with the same sign. - If the argument
xis positive infinity, then it returns +1.0. - If the argument
xis negative infinity, then it returns -1.0.
Example 1
public class JavaExample
{
public static void main(String[] args)
{
double x1 = 1.0;
double x2 = 0;
double x3 = -1.0;
//hyperbolic tangent of different double values.
System.out.println(Math.tanh(x1));
System.out.println(Math.tanh(x2));
System.out.println(Math.tanh(x3));
}
}
Output:

Example 2
public class JavaExample
{
public static void main(String[] args)
{
double x1 = Double.MAX_VALUE;
double x2 = Double.MIN_VALUE;
double x3 = 0.0/0; //NaN
System.out.println(Math.tanh(x1));
System.out.println(Math.tanh(x2));
System.out.println(Math.tanh(x3));
}
}
Output:

Example 3
public class JavaExample
{
public static void main(String[] args)
{
double x1 = Double.POSITIVE_INFINITY;
double x2 = Double.NEGATIVE_INFINITY;
double x3 = Math.PI;
System.out.println(Math.tanh(x1));
System.out.println(Math.tanh(x2));
System.out.println(Math.tanh(x3));
}
}
Output:
