C cosh() Function

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.
| Call | What 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
double cosh(double x);
float coshf(float x);
long double coshl(long double x);
Parameters
| Parameter | Description |
|---|
| x | Required. Any real double. It is not an angle. |
Return Value
| Return Value | Description |
|---|
| Hyperbolic cosine | A 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.
#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;
}
cosh(0) = 1.000000
cosh(1) = 1.543081
How It Works
- Include math.h. That declares
cosh. - cosh(0) is 1. The graph bottoms out at zero.
- cosh(1) grows. Already larger than 1 for a moderate input.
- Result is double. Print with
%.6f for readable precision.
Example 2 — Even Function Check
Negating the input does not change the result.
#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;
}
cosh(1.5) = 2.352410
cosh(-1.5) = 2.352410
same? yes
How It Works
- Compute both sides. Call
cosh with 1.5 and -1.5. - Formula is symmetric. Swapping
x and -x swaps the two exponentials, then averages them. - Values match. Equality holds for normal finite inputs.
- 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.
#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;
}
cosh(x) = 1.5430806348
(e^x+e^-x)/2 = 1.5430806348
How It Works
- Library call.
cosh(x) is the dedicated function. - Manual formula. Average
exp(x) and exp(-x). - Same number. For ordinary
x, both paths agree closely. - 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
Developer, cloud engineer, and technical writer
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