C++ std::sinh() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
<cmath>

Definition

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
CallWhat 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

ParameterDescription
xRequired. Any number. It is not an angle, so there is no radians or degrees question. An integer is converted to double.

Return Value

Return ValueDescription
Hyperbolic sineThe value of (ex - e-x) / 2. It has the same sign as x.
inf / -infFor a very large x (about 711 for a double) the result overflows to inf or -inf.
0sinh(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;
}

How It Works

  1. Each number in the array is passed to std::sinh() in turn.
  2. sinh(0) is 0. sinh(1) is 1.1752, a little more than the input.
  3. The function is odd, so sinh(-1) is exactly -1.1752, the same size with the opposite sign. At 2 the value is already 3.62686.

Example 2 — Check the Formula with exp()

The definition says sinh(x) = (e^x - e^-x) / 2. Compare your own version with std::sinh().

C++
#include <cmath>
#include <iostream>

int main() {
    double x = 1.5;

    double byHand = (std::exp(x) - std::exp(-x)) / 2.0;
    double byLibrary = std::sinh(x);

    std::cout << "Using exp:  " << byHand << '\n';
    std::cout << "std::sinh:  " << byLibrary << '\n';
    std::cout << "Same value: " << (std::abs(byHand - byLibrary) < 1e-12) << '\n';
    return 0;
}

How It Works

  1. The first line follows the formula: exp(1.5) minus exp(-1.5), divided by 2.
  2. The second line asks the library for the same number. Both print 2.12928.
  3. The difference is far below 1e-12, so the test prints 1. For tiny x std::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;
}

How It Works

  1. The value a = 2 describes how tight the cable is. A bigger a means a flatter cable.
  2. 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.
  3. 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.

Next: sqrt()

Keep going through the <cmath> functions. Square root of a number.

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

8 people found this page helpful