Learn and Learn

Learn And Learn - great place for tutorials, references and how-to

Java – Find Hyperbolic Cosine – cosh() Method – Examples & Explanation

java.lang.Math.cosh() method is used to find the hyperbolic cosine of a double value in Java for the given input (x – parameter).
The hyperbolic cosine of x is defined to be (e^x + e^-x)/2 where e is Euler’s number.
The computed result must be within 2.5 ulps of the exact result.

cosh() method exists in Math class of java.lang package.
Since: JDK1.5

 

Declaration of cosh() Method

The declaration of cosh() method is:

 

Syntax of cosh() Method

The syntax of cosh() method in Java is:

Example

Output:

1.1402383210764286

Example
By importing java.lang package the syntax of cosh() method can be used as:

Output:

1.1402383210764286

 

Error Handling

If the x parameter is not a number cosh() method returns an error.
If there is no argument (x – input value) passes to the method, the compiler will produce an error.Example

Output:
Error

 

Parameters of cosh() Method in Java

x – Where x is any valid double input value. This parameter is required.

 

Return Value of cosh() Method in Java

cosh() method returns the hyperbolic cosine of a double value for the given input (x – parameter).

 

Java cosh() Method Example 1


Output:

 

Java cosh() Method Example 2


Output:

 

Special Cases of cosh() Method in Java

f the argument is NaN, then the result is NaN.
If the argument is infinite, then the result is positive infinity.
If the argument is zero, then the result is 1.0.
Example

Output:

1.0
1.0
Infinity
Infinity
NaN

 

LearnAndLearn.com © 2018 - All rights reserved