Java Math cosh() method with Examples
Last Updated :
06 Apr, 2018
The java.lang.Math.cosh() returns the hyperbolic cosine of a double value passed to it as argument. The hyperbolic cosine of any value a is defined as,
(ea + e-a)/2
where e is Euler’s number.
If the argument is NaN, then the result is NaN. If the argument is infinity then the result will be positive infinity. If the argument is zero, then the result is one.
Syntax :
public static double cosh(double a)
Parameter :
a : the value whose hyperbolic cosine is to be returned.
Return :
This method returns the hyperbolic cosine value of the argument.
Example 1 : To show working of java.lang.Math.cosh() method.
import java.lang.Math;
class Gfg {
public static void main(String args[])
{
double a = 3.5 ;
System.out.println(Math.cosh(a));
a = 90.328 ;
System.out.println(Math.cosh(a));
}
}
|
Output:
16.572824671057315
8.470751974588509E38
Example 2 : To show working of java.lang.Math.cosh() method when argument is NaN or infinity.
import java.lang.Math;
public class GFG {
public static void main(String[] args)
{
double positiveInfinity =
Double.POSITIVE_INFINITY;
double negativeInfinity =
Double.NEGATIVE_INFINITY;
double nan = Double.NaN;
double result;
result = Math.cosh(negativeInfinity);
System.out.println(result);
result = Math.cosh(positiveInfinity);
System.out.println(result);
result = Math.cosh(nan);
System.out.println(result);
}
}
|
Output:
Infinity
Infinity
NaN
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...