Java Math cosh() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Java 5+

Definition

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
CallWhat 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

ParameterDescription
xThe number whose hyperbolic cosine is wanted. Not an angle.

Return Value

Return ValueDescription
doubleThe 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.

Compare with Similar Methods

The hyperbolic trio and the circular cosine:

MethodHow it differs
sinh(x)Hyperbolic sine: odd, passes through zero.
tanh(x)Hyperbolic tangent: sinh / cosh, between -1 and 1.
cos(a)The circular cosine: periodic, needs radians, between -1 and 1.
exp(x)The building block: cosh(x) = (exp(x) + exp(-x)) / 2.

Java Examples

Example 1 — The Hyperbolic Cosine Is Always at Least 1

Check the floor value at 0, the even symmetry, and a few arguments on both sides of zero.

Java
import java.util.Locale;

public class MathCoshBasics {
    public static void main(String[] args) {
        System.out.println("cosh(0.0) = " + Math.cosh(0.0));
        System.out.println("cosh(1.0)  = " + String.format(Locale.US, "%.4f", Math.cosh(1.0)));
        System.out.println("cosh(-1.0) = " + String.format(Locale.US, "%.4f", Math.cosh(-1.0)));
        System.out.println("even function? " + (Math.abs(Math.cosh(2) - Math.cosh(-2)) < 1e-12));
        System.out.println("cosh(-Infinity) = " + Math.cosh(Double.NEGATIVE_INFINITY));

        double[] values = {-3, -0.5, 0, 2};
        for (double v : values) {
            System.out.println("cosh(" + v + ") = " + String.format(Locale.US, "%.4f", Math.cosh(v))
                    + " (at least 1? " + (Math.cosh(v) >= 1) + ")");
        }
    }
}

How It Works

  1. 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.
  2. 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.
  3. 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);
    }
}

How It Works

  1. 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.
  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.
  3. 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));
    }
}

How It Works

  1. 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.
  2. 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.
  3. 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.

Next: decrementExact()

Subtract 1 from an int or long and throw ArithmeticException on overflow.

decrementExact() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

13 people found this page helpful