C Math acosh() Function

Beginner
⏱️ 9 min read
📚 Updated: Jul 2026
🎯 5 Examples
<math.h>

What You’ll Learn

The acosh() function computes the inverse hyperbolic cosine of a number. If you know a value x and want the hyperbolic angle t such that cosh(t) = x, acosh(x) gives you that answer—used in science, engineering, and advanced geometry.

01

Inverse cosh

Undo cosh().

02

math.h

Link with -lm.

03

Domain

x ≥ 1.

04

acosh(1)

Returns 0.

05

NaN

x < 1.

06

vs acos

Hyperbolic.

Definition and Usage

Hyperbolic cosine is defined as cosh(t) = (et + e−t) / 2. The inverse acosh(x) answers: “What value of t produces this cosh output?” Because cosh(t) ≥ 1 for all real t, acosh only accepts x ≥ 1.

Mathematically, for x ≥ 1: acosh(x) = ln(x + √(x² − 1)). The C library computes this precisely so you do not need to code the logarithm yourself.

💡
Beginner Tip

Do not confuse acosh() with acos(). acos works on cosine values between −1 and 1; acosh works on hyperbolic cosine values from 1 upward.

📝 Syntax

Standard C declaration:

C
double acosh(double x);

Related variants

C
float acoshf(float x);            /* <math.h> */
long double acoshl(long double x);  /* <math.h> */

Parameters

  • x — hyperbolic cosine value; must be ≥ 1.

Return Value

  • Non-negative real number: the value t such that cosh(t) = x.
  • acosh(1) returns 0.
  • If x < 1, returns NaN and may set errno to EDOM.

Headers and linking

  • #include <math.h>
  • Compile: gcc acosh.c -std=c11 -o acosh -lm

⚡ Quick Reference

CallMeaningResult (approx.)
acosh(1)cosh(0) = 10
acosh(2)cosh(t) = 21.316958
cosh(acosh(x))Inverse pairx (for x ≥ 1)
acosh(0.5)Below domainNaN
ln(x + sqrt(x*x-1))FormulaSame as acosh(x)
Inverse
acosh(x)

Angle from cosh

Forward
cosh(t)

Cosh from t

Valid x
x >= 1.0

Domain

Check
isnan(acosh(x))

Bad input

Examples Gallery

Compile every example with gcc file.c -std=c11 -o out -lm. Hyperbolic functions appear in physics and engineering formulas.

📚 Getting Started

Compute inverse hyperbolic cosine and print the result.

Example 1 — Basic Inverse Hyperbolic Cosine

Find t such that cosh(t) = 2.

C
#include <stdio.h>
#include <math.h>

int main(void) {
    double x = 2.0;
    double result = acosh(x);

    printf("acosh(%.1f) = %.6f\n", x, result);

    return 0;
}

How It Works

acosh(2) returns about 1.317 because cosh(1.317) ≈ 2. This matches the reference example, with cleaner output formatting.

Example 2 — Boundary Value acosh(1)

The smallest valid input returns zero.

C
#include <stdio.h>
#include <math.h>

int main(void) {
    printf("acosh(1) = %.6f\n", acosh(1.0));
    printf("cosh(0) = %.6f  (should equal 1)\n", cosh(0.0));

    return 0;
}

How It Works

cosh(0) = 1, so the inverse at the boundary is acosh(1) = 0. Values below 1 are not valid inputs.

📈 Practical Patterns

Error handling, inverse verification, and the underlying formula.

Example 3 — Detect Invalid Input (NaN)

Values less than 1 produce NaN—check before using the result.

C
#include <math.h>
#include <stdio.h>

int main(void) {
    double bad = 0.5;
    double result = acosh(bad);

    if (isnan(result)) {
        printf("acosh(%.1f) is undefined (NaN)\n", bad);
        printf("Input must be >= 1.0\n");
    } else {
        printf("acosh(%.1f) = %.6f\n", bad, result);
    }

    return 0;
}

How It Works

No real number has hyperbolic cosine 0.5. Use isnan() from <math.h> when input might come from user data or sensors.

Example 4 — Verify acosh() with cosh()

Forward and inverse hyperbolic cosine undo each other on valid inputs.

C
#include <stdio.h>
#include <math.h>

int main(void) {
    double values[] = { 1.0, 1.5, 2.0, 5.0, 10.0 };
    size_t i;

    for (i = 0; i < sizeof values / sizeof values[0]; i++) {
        double x = values[i];
        double t = acosh(x);
        double back = cosh(t);

        printf("x=%5.1f  acosh(x)=%.4f  cosh(acosh(x))=%.6f\n",
               x, t, back);
    }

    return 0;
}

How It Works

cosh(acosh(x)) should equal x when x ≥ 1. Tiny floating-point rounding may appear in the last decimal places.

Example 5 — Compare with the Logarithm Formula

See how the library result matches ln(x + √(x²−1)).

C
#include <math.h>
#include <stdio.h>

int main(void) {
    double x = 3.0;
    double lib = acosh(x);
    double manual = log(x + sqrt(x * x - 1.0));

    printf("acosh(%.1f)     = %.6f\n", x, lib);
    printf("ln(x+sqrt(x^2-1)) = %.6f\n", manual);

    return 0;
}

How It Works

Understanding the formula helps in math courses and debugging. In production code, prefer acosh() for accuracy and readability.

🚀 Common Use Cases

  • Special relativity — rapidity and hyperbolic angle calculations.
  • Catenary curves — shapes of hanging cables involve cosh and its inverse.
  • Signal processing — hyperbolic transforms in certain filter designs.
  • Scientific computing — solving equations where cosh(t) appears.
  • Pair with cosh() — recover a hyperbolic angle from a known cosh value.

🧠 How acosh() Works

1

Validate x ≥ 1

Reject values below 1 with NaN.

Domain
2

Apply inverse formula

Compute ln(x + √(x² − 1)) internally.

Compute
3

Return t ≥ 0

Principal non-negative hyperbolic angle.

Result
=

Hyperbolic angle

Use with cosh(), sinh(), or physics formulas.

📝 Notes

  • Domain is x ≥ 1; acosh(1) = 0.
  • Values below 1 return NaN—there is no real inverse in that range.
  • Not the same as acos() (circular inverse cosine).
  • Link with -lm when using GCC/Clang on Unix-like systems.
  • Use acoshf or acoshl for float or long double data.

⚡ Optimization

acosh() is implemented in the platform math library and is already optimized. Avoid recomputing it in loops when the input is unchanged. For very hot paths with float data, consider acoshf() to match your precision needs and reduce conversion overhead.

Conclusion

acosh() inverts hyperbolic cosine for inputs from 1 upward. Include <math.h>, link -lm, validate your domain, and pair it with cosh() when solving hyperbolic equations.

Continue with asin() for inverse circular sine, or explore cosh() for the forward hyperbolic cosine.

💡 Best Practices

✅ Do

  • Include <math.h> and link with -lm
  • Ensure x ≥ 1 before calling
  • Check isnan() on untrusted input
  • Verify with cosh(acosh(x)) while learning
  • Use acoshf for single-precision pipelines

❌ Don’t

  • Confuse acosh with acos
  • Pass values less than 1 without handling NaN
  • Forget -lm on Linux builds
  • Hand-code the log formula unless you have a special need
  • Assume output is in degrees—it is a hyperbolic angle

Key Takeaways

Knowledge Unlocked

Five things to remember about acosh()

Inverse hyperbolic cosine in C, explained simply.

5
Core concepts
📚 02

x ≥ 1

Valid domain.

Domain
🔢 03

acosh(1) = 0

Boundary.

Edge
⚠️ 04

NaN if x < 1

Invalid.

Safety
🔄 05

vs acos

Hyperbolic.

Compare

❓ Frequently Asked Questions

acosh() returns the inverse hyperbolic cosine of x. If cosh(t) = x, then acosh(x) = t. For example, acosh(2) is about 1.317 because cosh(1.317) ≈ 2.
Include <math.h> and link with -lm on many systems: gcc program.c -o program -lm. The function is declared as double acosh(double x).
x must be greater than or equal to 1. acosh(1) returns 0. If x < 1, acosh() returns NaN (Not a Number) and may set errno to EDOM.
No. acos() is inverse circular cosine (domain [-1, 1]). acosh() is inverse hyperbolic cosine (domain [1, ∞)). They solve different mathematical problems.
They are inverses on the valid domain: cosh(acosh(x)) equals x when x >= 1, and acosh(cosh(t)) equals |t| for non-negative t.
For x >= 1: acosh(x) = ln(x + sqrt(x*x - 1)). The library implements this accurately; you rarely code the formula by hand.
Did you know?

The shape of a hanging chain or cable is a catenary, described by cosh. When engineers know the height ratio at two points, they use acosh to recover the curve parameters—a real-world reason this function exists beyond textbook exercises.

Explore C Math Functions

Continue with asin() or browse the full math function reference.

Math Functions Index →

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.

3 people found this page helpful