In Java, the cosh() method is a part of the java.lang.Math class. This method is used to calculate the hyperbolic cosine of a given double value.
Mathematical Definition:
The hyperbolic cosine of any value a is defined as:
(ea + e-a)/2
where, e is Euler's number.
Special Cases: The cosh() method handles different cases, which are listed below,
- 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.
These special cases make sure that the Math.cosh() methods work correctly.
Syntax of cosh() Method
public static double cosh(double a)
- Parameter: This method takes a single parameter a, which is the value whose hyperbolic cosine is to be returned.
- Return Type: This method returns the hyperbolic cosine value of the argument.
Now, we are going to discuss some exampls for better understanding.
Examples of Java Math cosh() Method
Example 1: In this example, we will see the basic usage of cosh() method.
Java
// Java program to demonstrate working
// of Math.cosh() method
import java.lang.Math;
class Geeks {
public static void main(String args[]) {
double a = 3.5;
// Displaying hyperbolic cosine of 3.5
System.out.println(Math.cosh(a));
a = 90.328;
// Displaying hyperbolic cosine of 90.328
System.out.println(Math.cosh(a));
}
}
Output16.572824671057315
8.470751974588509E38
Explanation: Here, we are calculating the hyperbolic cosine of given numbers. First, we are calculating the hyperbolic cosine of 3.5 and after that we are calculating the cosine of 90.328.
Example 2: In this example, we will see how cosh() method handles NaN and Infinity.
Java
// Java program to demonstrate working
// Math.cosh() method with NaN and Infinity
import java.lang.Math;
public class Geeks {
public static void main(String[] args) {
double p = Double.POSITIVE_INFINITY;
double n = Double.NEGATIVE_INFINITY;
double nan = Double.NaN;
double res;
// here argument is negative infinity
res = Math.cosh(n);
System.out.println(res);
// here argument is positive infinity
res = Math.cosh(p);
System.out.println(res);
// here argument is NaN
res = Math.cosh(nan);
System.out.println(res);
}
}
OutputInfinity
Infinity
NaN
Similar Reads
Java Math cosh() method with Examples In Java, the cosh() method is a part of the java.lang.Math class. This method is used to calculate the hyperbolic cosine of a given double value.Mathematical Definition:The hyperbolic cosine of any value a is defined as:(ea + e-a)/2where, e is Euler's number. Special Cases: The cosh() method handles
2 min read
StrictMath cosh() Method in Java The java.lang.StrictMath.cosh() is an inbuilt method in Java which returns the hyperbolic cosine value of a given double argument. The method returns NaN when the argument is NaN. The method returns a positive infinity when the argument is infinity. The method returns 1.0 when the given argument is
2 min read
Java Math Class Java.lang.Math Class methods help to perform numeric operations like square, square root, cube, cube root, exponential and trigonometric operations.Declarationpublic final class Math extends Object Methods of Math Class in JavaMath class consists of methods that can perform mathematical operations a
7 min read
Java Math tanh() method with Examples In Java, the tanh() method is a part of the java.lang.Math class. This method returns the hyperbolic tangent of a double value passed to it as an argument. Mathematical Definition:The hyperbolic tangent of any value a is defined as:((ea - e-a)/2)/((ea + e-a)/2)where, e is Euler's number, whose value
2 min read
Java Math sinh() method with Examples In Java, the sinh() method is a part of the java.util.Math class. This method is used to calculate the hyperbolic sine of a given value. In this article, we are going to discuss how this method works for regular values and for special cases such as infinity and NaN.Mathematical Definition:The hyperb
3 min read
Set hashCode() Method in Java In Java, the hashCode() method is defined in the Object class and is used to generate a hash code for objects. It plays a very important role in hash-based collections like HashMap, HashSet, and HashTable. Example 1: This example demonstrates how hashCode() is used to get the hash code of the HashSe
2 min read
Java Math cosh() Method
min read