C Math cosh() Function

Beginner
⏱️ 9 min read
📚 Updated: Jul 2026
🎯 5 Examples
<math.h>

What You’ll Learn

The cosh() function computes the hyperbolic cosine of a real number. Built from exponentials—(ex + e−x) / 2—it always returns a value ≥ 1 and appears in physics, engineering, and special relativity formulas.

01

Hyperbolic

Not circular.

02

math.h

Link with -lm.

03

Any real x

Full domain.

04

Output ≥ 1

Min at 0.

05

Even fn

cosh(−x).

06

vs cos

Different.

Definition and Usage

Hyperbolic cosine is defined as cosh(x) = (ex + e−x) / 2, where e is Euler’s number (about 2.718). Unlike circular cos(), which oscillates between −1 and 1, cosh(x) grows smoothly and is always at least 1.

The input x is any real number—not a degree or radian angle in the circular sense. Think of it as a hyperbolic parameter. At x = 0, both exponentials contribute equally and cosh(0) = 1.

💡
Beginner Tip

Do not confuse cosh() with cos(). cos needs radians and returns values in [−1, 1]. cosh takes any real number and always returns ≥ 1. The inverse of cosh on outputs ≥ 1 is acosh().

📝 Syntax

Standard C declaration:

C
double cosh(double x);

Related variants

C
float coshf(float x);           /* <math.h> */
long double coshl(long double x); /* <math.h> */

Parameters

  • x — any real number (hyperbolic argument).

Return Value

  • Hyperbolic cosine of x, always ≥ 1.
  • cosh(0) returns 1.0.
  • cosh(1.5) returns about 2.352.
  • For very large |x|, result may overflow to infinity.

Headers and linking

  • #include <math.h>
  • Compile: gcc cosh.c -std=c11 -o cosh -lm

⚡ Quick Reference

CallMeaningResult (approx.)
cosh(0)Minimum value1.0
cosh(1)Standard value1.543
cosh(1.5)From old example2.352
cosh(-1.5)Even function2.352 (same)
acosh(cosh(x))Inverse pair|x|
Forward
cosh(x)

Hyperbolic cos

Inverse
acosh(y)

y ≥ 1 only

Formula
(exp(x)+exp(-x))/2

Exponential

Not this
cos(x)

Circular trig

Examples Gallery

Compile every example with gcc file.c -std=c11 -o out -lm. Hyperbolic functions pair naturally with exp() and sinh().

📚 Getting Started

Compute hyperbolic cosine and print the result.

Example 1 — Basic Hyperbolic Cosine

Calculate cosh(1.5) and display the result.

C
#include <math.h>
#include <stdio.h>

int main(void) {
    double x = 1.5;
    double result = cosh(x);

    printf("cosh(%.1f) = %.6f\n", x, result);

    return 0;
}

How It Works

The library evaluates (e1.5 + e−1.5) / 2 internally and returns about 2.352.

Example 2 — cosh(0) Equals 1

At zero, hyperbolic cosine reaches its minimum.

C
#include <math.h>
#include <stdio.h>

int main(void) {
    printf("cosh(0) = %.1f\n", cosh(0.0));

    return 0;
}

How It Works

When x = 0, e0 = 1, so cosh(0) = (1 + 1) / 2 = 1. This is the smallest value cosh can return.

📈 Practical Patterns

Symmetry, exponential formula, and comparison with cos.

Example 3 — Even Function: cosh(−x) = cosh(x)

Negative inputs work—and mirror positive ones.

C
#include <math.h>
#include <stdio.h>

int main(void) {
    double x = 1.5;

    printf("cosh( %.1f) = %.6f\n",  x, cosh(x));
    printf("cosh(%.1f) = %.6f\n", -x, cosh(-x));

    return 0;
}

How It Works

This corrects the old note that input must be from 0 to infinity. The domain is all reals, and cosh is symmetric about zero.

Example 4 — Verify with the Exponential Formula

Compute cosh(x) manually using exp() and compare.

C
#include <math.h>
#include <stdio.h>

int main(void) {
    double x = 2.0;
    double manual = (exp(x) + exp(-x)) / 2.0;
    double library = cosh(x);

    printf("x = %.1f\n", x);
    printf("Manual:   %.6f\n", manual);
    printf("cosh():   %.6f\n", library);

    return 0;
}

How It Works

The manual formula matches the library. In production code, prefer cosh()—it handles overflow and precision better than naive exp combinations for extreme values.

Example 5 — cosh() vs cos() at the Same Input

See why these are different functions despite similar names.

C
#define _USE_MATH_DEFINES
#include <math.h>
#include <stdio.h>

int main(void) {
    double vals[] = { 0.0, 1.0, 1.5, M_PI / 3 };
    size_t i;

    printf("    x     cosh(x)   cos(x)\n");
    for (i = 0; i < 4; i++) {
        double x = vals[i];
        printf("%5.2f  %8.4f  %8.4f\n", x, cosh(x), cos(x));
    }

    return 0;
}

How It Works

They only agree at x = 0 (both return 1). For other inputs, cosh grows while cos oscillates in [−1, 1]. Note: 1.05 is π/3 radians (60°) for the last row—cos needs radians; cosh does not.

🚀 Common Use Cases

  • Catenary curves — shape of a hanging cable: y = a · cosh(x/a).
  • Special relativity — Lorentz factor involves cosh in rapidity formulations.
  • Signal processing — hyperbolic functions in filter design.
  • Heat and diffusion — solutions to differential equations.
  • Pair with sinh() — hyperbolic identities like cosh²(x) − sinh²(x) = 1.

🧠 How cosh() Works

1

Receive real x

Any finite real number (positive, negative, or zero).

Input
2

Compute exponentials

Evaluate ex and e−x, average them.

Compute
3

Return ≥ 1

Result is a double always at least 1.0.

Output
=

Hyperbolic cosine

Use acosh(y) to reverse when y ≥ 1.

📝 Notes

  • Defined as (ex + e−x) / 2.
  • Domain: all real numbers (not just 0 to ∞).
  • Range: ≥ 1; minimum at cosh(0) = 1.
  • Even function: cosh(-x) == cosh(x).
  • Not the same as cos()—no degree/radian conversion needed.
  • Very large |x| may cause overflow; the library handles this gracefully.

⚡ Optimization

cosh() is implemented in the platform math library with careful handling of overflow. Avoid rewriting it as (exp(x) + exp(-x)) / 2 in hot loops—direct exp calls can overflow sooner. Use coshf when float precision is sufficient to save memory bandwidth.

Conclusion

cosh() computes hyperbolic cosine from exponentials, accepts any real input, and always returns a value ≥ 1. It is distinct from circular cos() and pairs with acosh() as its inverse on outputs ≥ 1.

Continue with exp() to explore exponentials further, or review acosh() for the inverse operation.

💡 Best Practices

✅ Do

  • Include <math.h> and link with -lm
  • Use cosh() instead of manual exp formulas
  • Remember output is always ≥ 1
  • Use acosh() to invert when y ≥ 1
  • Pair with sinh() for hyperbolic identities

❌ Don’t

  • Confuse cosh() with cos()
  • Convert degrees/radians before calling cosh()
  • Assume input must be non-negative
  • Expect output in [−1, 1] like circular cosine
  • Call acosh() on values below 1

Key Takeaways

Knowledge Unlocked

Five things to remember about cosh()

Hyperbolic cosine in C, explained simply.

5
Core concepts
📚 02

Output ≥ 1

Min at 0.

Range
📈 03

Formula

(e^x+e^-x)/2.

Math
📄 04

Even fn

All reals in.

Property
🔄 05

Inverse

acosh(y).

Pair

❓ Frequently Asked Questions

cosh() returns the hyperbolic cosine of x, computed as (e^x + e^(-x)) / 2. For example, cosh(0) is 1.0 and cosh(1.5) is about 2.352. It is not the same as the circular cosine function cos().
Include <math.h> and link with -lm on many systems: gcc program.c -o program -lm. The function is declared as double cosh(double x).
Neither in the usual trig sense. cosh(x) takes any real number x as a hyperbolic argument. You do not convert degrees to radians before calling cosh() the way you do for cos().
The result is always greater than or equal to 1. cosh(0) is exactly 1 (the minimum). As |x| grows, cosh(x) grows rapidly toward infinity.
cos() is circular trigonometry (input in radians, output in [-1, 1]). cosh() is hyperbolic (input is any real, output >= 1). They share a similar name but solve different math problems.
Yes. The domain is all real numbers. cosh() is an even function: cosh(-x) equals cosh(x). The old claim that input must be from 0 to infinity is incorrect.
Did you know?

A hanging chain or cable forms a catenary curve described by y = a · cosh(x/a). Architects have used this shape for centuries—the Gateway Arch in St. Louis is a famous scaled catenary, not a parabola.

Explore C Math Functions

Continue with exp() or browse the full math function reference.

Math Functions Index →

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.

5 people found this page helpful