C cosh() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
math.h

Definition

In C, cosh() returns the hyperbolic cosine of x. It is not an angle. cosh(0) is 1, and every other real input gives a larger result.

You pass one double. The result is a double that is 1 or greater. Include <math.h>.

Syntax

Pass any real number. Start with this call.

C
cosh(0.0);
CallWhat it does
cosh(0.0)Returns 1, the smallest result this function gives.

Include <math.h>. On GCC, link with -lm. x is not an angle in degrees.

Library declarations
C
double cosh(double x);
float coshf(float x);
long double coshl(long double x);

Parameters

ParameterDescription
xRequired. Any real double. It is not an angle.

Return Value

Return ValueDescription
Hyperbolic cosineA double that is 1 or greater.

C Examples

Example 1 — Basic Hyperbolic Cosine

Print cosh(0) and cosh(1) to see the minimum and a typical growth value.

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

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

How It Works

  1. Include math.h. That declares cosh.
  2. cosh(0) is 1. The graph bottoms out at zero.
  3. cosh(1) grows. Already larger than 1 for a moderate input.
  4. Result is double. Print with %.6f for readable precision.

Example 2 — Even Function Check

Negating the input does not change the result.

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

int main(void) {
    double a = cosh(1.5);
    double b = cosh(-1.5);

    printf("cosh(1.5)  = %.6f\n", a);
    printf("cosh(-1.5) = %.6f\n", b);
    printf("same? %s\n", a == b ? "yes" : "no");

    return 0;
}

How It Works

  1. Compute both sides. Call cosh with 1.5 and -1.5.
  2. Formula is symmetric. Swapping x and -x swaps the two exponentials, then averages them.
  3. Values match. Equality holds for normal finite inputs.
  4. Domain tip. Negatives are fully valid—no need to take absolute value first.

Example 3 — Verify With exp()

Rebuild the definition using exp and compare with cosh.

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

int main(void) {
    double x = 1.0;
    double via_cosh = cosh(x);
    double via_exp = (exp(x) + exp(-x)) / 2.0;

    printf("cosh(x)     = %.10f\n", via_cosh);
    printf("(e^x+e^-x)/2 = %.10f\n", via_exp);

    return 0;
}

How It Works

  1. Library call. cosh(x) is the dedicated function.
  2. Manual formula. Average exp(x) and exp(-x).
  3. Same number. For ordinary x, both paths agree closely.
  4. Prefer cosh. The library version is clearer and often better conditioned for extreme inputs.

Frequently Asked Questions

cosh() returns the hyperbolic cosine of x. cosh(0) is 1, and other real inputs are greater than 1.
x is required. Any real double is allowed. It is not an angle.
A double that is 1 or greater.
Include <math.h>. On GCC, link with -lm.
No. cos() takes an angle in radians. cosh() is the hyperbolic cosine.

Next: exp()

Compute e^x—the building block behind hyperbolic identities.

exp() 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.

9 people found this page helpful