CKTIS / C
cosh — C23 mathematical function
`cosh(x)` from `<math.h>` returns the hyperbolic cosine of `x`, mathematically `(e^x + e^-x) / 2`. The function is even; C23 requires a range error when the magnitude of finite `x` is too large.
Version: C23
Syntax
double cosh(double x);cosh(x) from <math.h> returns the hyperbolic cosine of x, mathematically (e^x + e^-x) / 2. The function is even; C23 requires a range error when the magnitude of finite x is too large.
The example calls cosh(0.0) and cosh(1.0). Output 1.000 1.543 shows the function’s minimum at zero and the rounded value near 1.543 at one.
Use cosh rather than manually composing two exp calls, which can have worse numerical behavior. Handle overflow through the implementation’s math_errhandling; the guarantees cosh(±0) = 1 and cosh(±∞) = +∞ are Annex F/IEC 60559 details.
Examples
#include <math.h>
#include <stdio.h>
int main(void) {
printf("%.3f %.3f\n", cosh(0.0), cosh(1.0));
return 0;
}
Result
1.000 1.543
The example calls `cosh(0.0)` and `cosh(1.0)`. Output `1.000 1.543` shows the function’s minimum at zero and the rounded value near 1.543 at one.