In Java, Math.cosh(x) returns the hyperbolic cosine of x, defined as (ex + e-x) / 2. The argument is a plain number, not an angle. Math.cosh(0) is 1.0, and the value never drops below 1.
The function is even (cosh(-x) = cosh(x)) and rises like a bowl on both sides of zero. That bowl is the shape of a chain or cable hanging between two posts, called a catenary, which is the classic use. It was added in Java 5.
A static method of the java.lang.Math class, added in Java 5 (JDK 1.5). Call it on the class name, as in Math.cosh(...). No import is needed, because classes in java.lang are always visible.
Syntax
Pass any double. The hyperbolic cosine comes back as a double, at least 1.0.
Java
double a = Math.cosh(0.0); // 1.0
double b = Math.cosh(1.0); // about 1.5431
double c = Math.cosh(-1.0); // about 1.5431
double y = a0 * Math.cosh(x / a0); // catenary height
Call
What it does
Math.cosh(0.0)
The lowest point of the curve: returns 1.0.
Math.cosh(-2.0)
Same as cosh(2.0), about 3.7622.
Math.cosh(Double.NEGATIVE_INFINITY)
Returns positive Infinity.
Math.cosh(1000.0)
Too large for a double: returns Infinity.
There is only a double version and no restricted domain. Unlike the circular cosine, cosh is not periodic and is not limited to -1..1.
Library declarations
Java
// java.lang.Math
public static double cosh(double x)
Parameters
Parameter
Description
x
The number whose hyperbolic cosine is wanted. Not an angle.
Return Value
Return Value
Description
double
The hyperbolic cosine of x, always 1.0 or greater. The result is NaN if x is NaN, and positive Infinity if x is infinite or too large.
cosh(0.0) = 1.0
cosh(1.0) = 1.5431
cosh(-1.0) = 1.5431
even function? true
cosh(-Infinity) = Infinity
cosh(-3.0) = 10.0677 (at least 1? true)
cosh(-0.5) = 1.1276 (at least 1? true)
cosh(0.0) = 1.0000 (at least 1? true)
cosh(2.0) = 3.7622 (at least 1? true)
How It Works
The bottom of the bowl. At 0 the average of e0 and e-0 is exactly 1.0, the smallest value the function ever takes.
Both sides agree. -1.0 and 1.0 print the same 1.5431, and cosh(2) and cosh(-2) differ by far less than 1e-12.
Even infinity is positive. One of the two exponentials always blows up, so -Infinity gives Infinity; the loop also confirms every sample is at least 1, with 10.0677 at -3.
Example 2 — The Identity cosh(x)^2 - sinh(x)^2 = 1
For every x the difference of the squares is exactly 1 on paper. Test it for four values, printing the pieces rounded.
Java
import java.util.Locale;
public class MathCoshIdentity {
public static void main(String[] args) {
double[] xs = {0.5, 1, 2, 3};
boolean allOne = true;
for (double x : xs) {
double c = Math.cosh(x);
double s = Math.sinh(x);
double diff = c * c - s * s;
allOne = allOne && Math.abs(diff - 1) < 1e-9;
System.out.println(String.format(Locale.US, "x=%.1f: cosh=%.4f sinh=%.4f diff=%.6f", x, c, s, diff));
}
System.out.println("always 1 within 1e-9? " + allOne);
}
}
The two curves hug each other. As x grows, cosh and sinh get closer (10.0677 against 10.0179 at x = 3), because both are dominated by ex / 2.
Squares keep the gap at 1. The squares are huge (about 101.4 and 100.4 at x = 3), yet their difference stays 1; %.6f shows the identity holds to six decimals.
Do not expect exact equality. Subtracting two large squares leaves a double a few ulps away from 1.0 (for example 0.9999999999999716 near x = 3), so the check uses a tolerance of 1e-9.
Example 3 — The Height of a Hanging Cable (Catenary)
A cable between two posts follows y = a * cosh(x / a), where x is measured sideways from the lowest point and a is 50. See how far it rises toward the posts.
Java
import java.util.Locale;
public class MathCoshCatenary {
public static void main(String[] args) {
double a = 50.0;
int[] sideways = {0, 10, 20, 30};
for (int x : sideways) {
double height = a * Math.cosh(x / a);
System.out.println(String.format(Locale.US, "%2d m from the middle -> height %.2f m", x, height));
}
double sag = a * Math.cosh(30 / a) - a;
System.out.println(String.format(Locale.US, "Cable at 30 m is %.2f m above its lowest point", sag));
}
}
Output
0 m from the middle -> height 50.00 m
10 m from the middle -> height 51.00 m
20 m from the middle -> height 54.05 m
30 m from the middle -> height 59.27 m
Cable at 30 m is 9.27 m above its lowest point
How It Works
The curve starts at a. At the middle cosh(0) is 1, so the lowest point of the cable is exactly a * 1 = 50.00 m.
Slow, then steep. Moving 10 m sideways lifts it only 1.00 m, but 30 m sideways lifts it 9.27 m: a catenary flattens at the bottom and steepens toward the posts.
Subtract for the sag.a * cosh(30 / a) - a is the height gained between the lowest point and a post 30 m away; the integer 30 divides as a double because a is a double.
Frequently Asked Questions
It returns the hyperbolic cosine of a double, defined as (e^x + e^-x) / 2. Math.cosh(0) is 1.0 and the result is never below 1.
It is the average of e^x and e^-x. Those two numbers multiply to 1, and their average cannot be below 1; the minimum occurs at x = 0.
It describes the hanging-cable curve called a catenary, y = a * cosh(x / a), and it appears in physics, engineering, and some numerical formulas.
No. cos takes an angle in radians and stays between -1 and 1. cosh takes any number and grows without limit.
Infinity, once the true result exceeds the largest double, which happens for values above roughly 710 in either direction. No exception is thrown.