Java Math cosh() Method
The cosh() method of Math class returns the first hyperbolic cosine((e+e)/2) of a double value.
Syntax:
public static double cosh(double x)
Parameters:
The parameter ‘x’ represents the number whose hyperbolic cosine is to be determined.
Return Value:
The cosh() method returns the hyperbolic cosine of x.
Special cases of the cosh() method are as follows:
- It returns NaN, is the argument passed is NaN.
- It returns positive infinity, if the argument passed is infinite.
- It returns 1.0, if the argument passed is zero.
Example 1:
public class JavaMathCoshExample1 {
public static void main(String[] args) {
double a=90;
//returns the hyperbolic cosine value for a
System.out.println("Hyperbolic cosine value : "+Math.cosh(a));
}
}
Output:
Hyperbolic cosine value : 6.102016471589204E38
Example 2:
public class JavaMathCoshExample2 {
public static void main(String[] args) {
double a=-0.0d/0.0d;
//It returns NaN, is the argument passed is NaN
System.out.println("Hyperbolic cosine value : "+Math.cosh(a));
}
}
Output:
Hyperbolic cosine value : NaN
Example 3:
public class JavaMathCoshExample3 {
public static void main(String[] args) {
// It returns 1.0, if the argument passed is zero
double x = 0;
System.out.println("Hyperbolic cosine value : "+Math.cosh(x));
}
}
Output:
Hyperbolic cosine value : 1.0
Example 4:
public class JavaMathCoshExample4 {
public static void main(String[] args) {
// returns positive infinity, if the argument passed is infinite
double x = 3.0/0.0d;
System.out.println("1. Hyperbolic cosine value for "+x+":
"+Math.cosh(x));
// returns positive infinity, if the argument passed is a
negative infinite
double y = -3.0/0.0d;
System.out.println("2. Hyperbolic cosine value for "+y+ " :
"+Math.cosh(y));
}
}
Output:
1.Hyperbolic cosine value for Infinity: Infinity 2.Hyperbolic cosine value for -Infinity : Infinity
