In C++, std::sinh(x) is the hyperbolic sine. It is built from the number e: sinh(x) = (ex - e-x) / 2. It looks a little like a straight line near zero and then climbs very fast.
It has nothing to do with angles in a right triangle. The name is only similar to std::sin(). Hyperbolic functions appear in the shape of a hanging cable, in physics, and in some machine-learning formulas. You can give it any number, positive or negative.
std::sinh() is declared in <cmath> and is part of the group Hyperbolic functions. Hyperbolic functions are built from ex. They are not about angles, but they have the same names with an h added.
Syntax
Include <cmath> and call std::sinh. Start with these lines.
C++
double a = std::sinh(1.0); // double version
float b = std::sinh(1.0f); // float version
Call
What it does
std::sinh(1.0)
Passes a double and returns a double. Here the result is 1.1752.
std::sinh(1.0f)
Passes a float, so the float overload runs and returns a float.
std::sinh(0)
An integer is converted to double. Returns 0 as a double.
Write std::sinh so the C++ overloads for float, double, and long double are used.
Library declarations
C++
float sinh(float x);
double sinh(double x);
long double sinh(long double x);
double sinh(Integer x); // for integer types
Parameters
Parameter
Description
x
Required. Any number. It is not an angle, so there is no radians or degrees question. An integer is converted to double.
Return Value
Return Value
Description
Hyperbolic sine
The value of (ex - e-x) / 2. It has the same sign as x.
inf / -inf
For a very large x (about 711 for a double) the result overflows to inf or -inf.
0
sinh(0) is exactly 0.
C++ Examples
Example 1 — Hyperbolic Sine of Common Values
Print sinh() for a few numbers, including a negative one.
C++
#include <cmath>
#include <iostream>
int main() {
double values[] = {0.0, 1.0, -1.0, 2.0};
for (double v : values) {
std::cout << "sinh(" << v << ") = " << std::sinh(v) << '\n';
}
return 0;
}
Using exp: 2.12928
std::sinh: 2.12928
Same value: 1
How It Works
The first line follows the formula: exp(1.5) minus exp(-1.5), divided by 2.
The second line asks the library for the same number. Both print 2.12928.
The difference is far below 1e-12, so the test prints 1. For tiny xstd::sinh() is more accurate than the formula.
Example 3 — Length of a Hanging Cable
A hanging cable follows a curve called the catenary. The length from the lowest point to a horizontal distance x is a * sinh(x / a).
C++
#include <cmath>
#include <iostream>
int main() {
double a = 2.0;
for (double x : {1.0, 2.0, 4.0}) {
double length = a * std::sinh(x / a);
std::cout << "Distance " << x << " m: cable " << length << " m\n";
}
return 0;
}
Output
Distance 1 m: cable 1.04219 m
Distance 2 m: cable 2.3504 m
Distance 4 m: cable 7.25372 m
How It Works
The value a = 2 describes how tight the cable is. A bigger a means a flatter cable.
For a distance of 1, the cable is 2 * sinh(0.5), or 1.04219 m. This is a little longer than the straight 1 m.
The gap between cable length and distance grows as the cable goes farther from the lowest point: 2.3504 m at 2 m and 7.25372 m at 4 m.
Frequently Asked Questions
std::sinh(x) returns the hyperbolic sine of x, which is (e^x - e^-x) / 2. It grows quickly for large positive x.
The hyperbolic sine as float, double, or long double. sinh(0) is 0, and a very large x gives inf with the same sign as x.
No. sin() works with angles in radians and gives values from -1 to 1. sinh() is the hyperbolic sine, built from e^x, and it can be any size.
sinh(x) = (e^x - e^-x) / 2. It is an odd function, so sinh(-x) is -sinh(x).
Include <cmath> and write std::sinh(). That always works and picks the C++ overloads. The global name ::sinh often works too, but the standard does not promise it, and it may only take a double.