What is Math.cosh() in Java?
Java has a built-in Math class, defined in the java.lang package, which contains important functions to perform basic mathematical operations. The class has the cosh() method, which is used to compute a specified angle’s hyperbolic cosine.
Syntax
public static double cosh(double angle);
Parameter
The function takes in one single parameter, which is described below.
anglerepresents the double value corresponding to the angle in radians for which we have to find the hyperbolic cosine.
Return value
The function returns the double value corresponding to the hyperbolic cosine of the angle.
-
If the value of
angleis then the return value isNaN not a number NaN. -
If the value of
angleis positive/negative infinity, then the return value ispositive infinity.
Code
To convert an angle measured in degrees to an equivalent angle measured in radians, we use can use the built-in
Math.toRadians(double angle_in_degrees)method.
import java.lang.Math;class HelloWorld {public static void main( String args[] ) {double param = Math.toRadians(30);double result = Math.cosh(param);System.out.println("cosh(" + param + ") = " + result);param = Math.toRadians(45);result = Math.cosh(param);System.out.println("cosh(" + param + ") = " + result);param = Math.toRadians(60);result = Math.cosh(param);System.out.println("cosh(" + param + ") = " + result);param = Math.toRadians(90);result = Math.cosh(param);System.out.println("cosh(" + param + ") = " + result);result = Math.cosh(Double.POSITIVE_INFINITY);System.out.println("cosh(∞) = " + result);result = Math.cosh(Double.NEGATIVE_INFINITY);System.out.println("cosh(-∞) = " + result);result = Math.cosh(Double.NaN);System.out.println("cosh(NaN) = " + result);}}