Java Math.cosh() method returns hyperbolic cosine of the given value. This method accepts double type value as an argument and returns the hyperbolic cosine of this value as a result. Hyperbolic cosine of a value x is defined as (ex + e-x)/2, where e is the Euler’s number whose value is 2.718281828459045.
public class JavaExample
{
public static void main(String[] args)
{
double x = 1;
System.out.println(Math.cosh(x));
}
}
Output:
1.543080634815244
Syntax of Math.cosh() method
Math.cosh(0); //returns 1.0
cosh() Description
public static double cosh(double x): It returns hyperbolic cosine of the given value (argument) x.
cosh() Parameters
- x: A double value whose hyperbolic cosine is to be determined.
cosh() Return Value
- Returns hyperbolic cosine of argument
x. - If argument
xis NaN (Not a number), then it returns NaN. - If argument
xis infinite, then it returns positive infinity. - If the argument
xis zero, 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 cosine of different double values.
System.out.println(Math.cosh(x1));
System.out.println(Math.cosh(x2));
System.out.println(Math.cosh(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.cosh(x1));
System.out.println(Math.cosh(x2));
System.out.println(Math.cosh(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.cosh(x1));
System.out.println(Math.cosh(x2));
System.out.println(Math.cosh(x3));
}
}
Output:
