C++ std::acosh() Function

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

Definition

In C++, std::acosh(x) is the inverse hyperbolic cosine. It undoes std::cosh(). Since cosh(0) is 1, acosh(1) is 0. Since cosh(2) is about 3.7622, acosh(3.7622) gives 2.

The function only works for inputs of 1 or more, because cosh() never goes below 1. It returns the non-negative answer. The negative answer, -acosh(x), also has the same cosh, so you add the sign yourself if you need it.

std::acosh() 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::acosh. Start with these lines.

C++
double a = std::acosh(2.0);    // double version
float  b = std::acosh(2.0f);   // float version
CallWhat it does
std::acosh(2.0)Passes a double and returns a double. Here the result is 1.31696.
std::acosh(2.0f)Passes a float, so the float overload runs and returns a float.
std::acosh(1)An integer is converted to double. Returns 0 as a double.

Write std::acosh so the C++ overloads for float, double, and long double are used.

Library declarations
C++
float       acosh(float x);
double      acosh(double x);
long double acosh(long double x);
double      acosh(Integer x);   // for integer types

Parameters

ParameterDescription
xRequired. A number that is 1 or more. Smaller numbers are outside the domain. An integer is converted to double.

Return Value

Return ValueDescription
Inverse coshA non-negative number whose hyperbolic cosine is x.
NaNReturned when x is less than 1. This is a domain error.
0 / infacosh(1) is 0, and acosh(inf) is inf.

C++ Examples

Example 1 — Inverse Hyperbolic Cosine of Common Values

Print acosh() for numbers of 1 and above.

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

int main() {
    double values[] = {1.0, 2.0, 10.0, 100.0};

    for (double v : values) {
        std::cout << "acosh(" << v << ") = " << std::acosh(v) << '\n';
    }
    return 0;
}

How It Works

  1. All four inputs are at least 1, so each is inside the domain.
  2. acosh(1) is exactly 0, the smallest possible answer. acosh(2) is 1.31696.
  3. The answer grows slowly, like a logarithm. A hundred times 1 gives only 5.29829, and 10 gives 2.99322.

Example 2 — Inputs Below 1

See what acosh() returns outside its domain and at the edge.

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

int main() {
    std::cout << "acosh(1) = " << std::acosh(1.0) << '\n';
    std::cout << "acosh(0.5) is NaN: " << std::isnan(std::acosh(0.5)) << '\n';
    std::cout << "acosh(-2) is NaN:  " << std::isnan(std::acosh(-2.0)) << '\n';
    return 0;
}

How It Works

  1. The edge value 1 is allowed, and the result is exactly 0.
  2. 0.5 is below the edge. No number has a hyperbolic cosine of 0.5, so the result is NaN and std::isnan() prints 1.
  3. A negative input like -2 is also outside the domain, so the answer is NaN too. The program keeps running.

Example 3 — Where Does the Cable Reach a Height

A hanging cable has height y = a * cosh(x / a). Turn that around to find the distance x for a given height: x = a * acosh(y / a).

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

int main() {
    double a = 2.0;

    for (double y : {2.0, 5.0, 10.0}) {
        double x = a * std::acosh(y / a);
        std::cout << "Height " << y << ": x = " << x << '\n';
    }
    return 0;
}

How It Works

  1. y / a turns the height into a number that is at least 1, which is what acosh() needs. The lowest point of the cable has y = a.
  2. At height 2 the ratio is 1, and acosh(1) is 0. So x is 0, the bottom of the curve.
  3. A height of 5 gives x = 3.1336, and a height of 10 gives x = 4.58486. A cable height below a would give NaN.

Frequently Asked Questions

std::acosh(x) returns the inverse hyperbolic cosine of x. The input must be 1 or more, and the result is 0 or more.
The non-negative inverse hyperbolic cosine as float, double, or long double. If x is less than 1, the result is NaN.
Numbers that are 1 or more. Values below 1 give NaN, because the hyperbolic cosine is never smaller than 1.
cosh() gives the same answer for x and -x, so the inverse has two answers. acosh() returns the non-negative one. Use -acosh(x) for the negative one.
Include <cmath> and write std::acosh(). That always works and picks the C++ overloads. The global name ::acosh often works too, but the standard does not promise it, and it may only take a double.

Next: asin()

Keep going through the <cmath> functions. Inverse sine, as an angle in radians.

asin() 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