C Math atanh() Function

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

What You’ll Learn

The atanh() function computes the inverse hyperbolic tangent of a number. If you know a value x between −1 and 1 and want the hyperbolic angle t such that tanh(t) = x, atanh(x) gives you that answer.

01

Inverse tanh

Undo tanh().

02

math.h

Link with -lm.

03

Domain

(−1, 1).

04

atanh(0)

Returns 0.

05

NaN

|x| ≥ 1.

06

vs atan

Hyperbolic.

Definition and Usage

Hyperbolic tangent is defined as tanh(t) = sinh(t) / cosh(t). Its output is always between −1 and 1. The inverse atanh(x) recovers the value t such that tanh(t) = x.

Mathematically, for |x| < 1: atanh(x) = ½ ln((1 + x) / (1 − x)). Because tanh never reaches ±1, atanh cannot accept |x| ≥ 1 as finite input.

💡
Beginner Tip

Do not confuse atanh() with atan(). atan works on any real slope; atanh only accepts values strictly between −1 and 1.

📝 Syntax

Standard C declaration:

C
double atanh(double x);

Related variants

C
float atanhf(float x);            /* <math.h> */
long double atanhl(long double x); /* <math.h> */

Parameters

  • x — hyperbolic tangent value; must satisfy |x| < 1.

Return Value

  • Real number t such that tanh(t) = x.
  • atanh(0) returns 0.
  • If |x| ≥ 1, returns NaN and may set errno to EDOM.

Headers and linking

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

⚡ Quick Reference

CallMeaningResult (approx.)
atanh(0)tanh(0) = 00
atanh(0.5)tanh(t) = 0.50.5493
atanh(-0.5)Odd symmetry-0.5493
atanh(0.99)Near boundary2.6467
atanh(1.0)Out of domainNaN
Inverse
atanh(x)

Angle from tanh

Forward
tanh(t)

Tanh from t

Valid x
|x| < 1.0

Open interval

Formula
0.5*log((1+x)/(1-x))

ln form

Examples Gallery

Compile every example with gcc file.c -std=c11 -o out -lm. Keep |x| < 1 for valid results.

📚 Getting Started

Compute inverse hyperbolic tangent of 0.5.

Example 1 — Basic Inverse Hyperbolic Tangent

Find t such that tanh(t) = 0.5.

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

int main(void) {
    double x = 0.5;
    double result = atanh(x);

    printf("Inverse hyperbolic tangent of %.1f: %.6f\n", x, result);

    return 0;
}

How It Works

atanh(0.5) returns about 0.549 because tanh(0.549) ≈ 0.5. This matches the reference example with clearer formatting.

Example 2 — Zero and Odd Symmetry

atanh is an odd function: atanh(−x) = −atanh(x).

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

int main(void) {
    double x = 0.5;

    printf("atanh(0)    = %.6f\n", atanh(0.0));
    printf("atanh(%.1f) = %.6f\n", x, atanh(x));
    printf("atanh(-%.1f) = %.6f\n", x, atanh(-x));

    return 0;
}

How It Works

Negative inputs are valid as long as |x| < 1. The result flips sign, mirroring the behavior of tanh.

📈 Practical Patterns

Error handling, inverse verification, and the logarithm formula.

Example 3 — Detect Invalid Input (|x| ≥ 1)

Values at or beyond ±1 are outside the domain.

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

int main(void) {
    double bad = 1.0;
    double result = atanh(bad);

    if (isnan(result)) {
        printf("atanh(%.1f) is undefined (NaN)\n", bad);
        printf("Input must satisfy |x| < 1.0\n");
    } else {
        printf("atanh(%.1f) = %.6f\n", bad, result);
    }

    return 0;
}

How It Works

tanh(t) asymptotically approaches ±1 but never equals it. atanh(1) has no finite real solution—the library returns NaN.

Example 4 — Verify atanh() with tanh()

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

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

int main(void) {
    double values[] = { -0.8, -0.3, 0.0, 0.3, 0.8 };
    size_t i;

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

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

    return 0;
}

How It Works

tanh(atanh(x)) should equal x when |x| < 1. This is the best sanity check while learning.

Example 5 — Compare with the Logarithm Formula

See how the library matches ½ ln((1+x)/(1−x)).

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

int main(void) {
    double x = 0.5;
    double lib = atanh(x);
    double manual = 0.5 * log((1.0 + x) / (1.0 - x));

    printf("atanh(%.1f)              = %.6f\n", x, lib);
    printf("0.5*log((1+x)/(1-x))     = %.6f\n", manual);

    return 0;
}

How It Works

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

🚀 Common Use Cases

  • Statistics — Fisher’s z-transform uses atanh on correlation coefficients.
  • Machine learning — inverse of sigmoid-like functions bounded in (−1, 1).
  • Physics — equations involving hyperbolic flow or relativistic velocity composition.
  • Scientific computing — solving equations where tanh(t) appears.
  • Pair with tanh() — recover a hyperbolic angle from a known tanh value.

🧠 How atanh() Works

1

Validate |x| < 1

Reject |x| ≥ 1 with NaN.

Domain
2

Apply inverse formula

Compute ½ ln((1+x)/(1−x)) internally.

Compute
3

Return real t

Hyperbolic angle with tanh(t) = x.

Result
=

Hyperbolic angle

Use with tanh(), sinh(), or statistics formulas.

📝 Notes

  • Domain is the open interval (−1, 1)—endpoints ±1 are invalid.
  • Returns the inverse hyperbolic tangent, not the forward tanh value.
  • Not the same as atan() (circular inverse tangent).
  • Link with -lm when using GCC/Clang on Unix-like systems.
  • Use atanhf or atanhl for float or long double data.

⚡ Optimization

atanh() is implemented in the platform math library and is already optimized. Validate input range once before batch processing. For float pipelines, use atanhf() to avoid unnecessary promotion to double.

Conclusion

atanh() inverts hyperbolic tangent for values strictly between −1 and 1. Include <math.h>, link -lm, validate your domain, and pair it with tanh() when solving hyperbolic equations.

Continue with cbrt() for cube roots, or explore tanh() for the forward hyperbolic tangent.

💡 Best Practices

✅ Do

  • Include <math.h> and link with -lm
  • Ensure |x| < 1 before calling
  • Check isnan() on untrusted input
  • Verify with tanh(atanh(x)) while learning
  • Use atanhf for single-precision data

❌ Don’t

  • Confuse atanh with atan
  • Pass x = 1 or x = -1 expecting a finite result
  • Think the return value is a tanh output
  • Forget -lm on Linux builds
  • Hand-code the log formula unless you have a special need

Key Takeaways

Knowledge Unlocked

Five things to remember about atanh()

Inverse hyperbolic tangent in C, explained simply.

5
Core concepts
🔢 02

(-1, 1)

Open domain.

Domain
📈 03

atanh(0) = 0

Identity.

Edge
⚠️ 04

|x| ≥ 1

NaN.

Safety
🔄 05

vs atan

Hyperbolic.

Compare

❓ Frequently Asked Questions

atanh() returns the inverse hyperbolic tangent of x. If tanh(t) = x, then atanh(x) = t. For example, atanh(0.5) is about 0.549 because tanh(0.549) ≈ 0.5.
Include <math.h> and link with -lm on many systems: gcc program.c -o program -lm. The function is declared as double atanh(double x).
x must be strictly between -1 and 1 (|x| < 1). atanh(0) returns 0. If |x| >= 1, atanh() returns NaN and may set errno to EDOM.
No. atan() is inverse circular tangent (any real x, range -pi/2 to pi/2). atanh() is inverse hyperbolic tangent (domain -1 to 1). They solve different problems.
They are inverses on the valid domain: tanh(atanh(x)) equals x when |x| < 1, and atanh(tanh(t)) equals t for every real t.
For |x| < 1: atanh(x) = 0.5 * ln((1 + x) / (1 - x)). The library implements this accurately; you rarely code the formula by hand.
Did you know?

Fisher’s z-transformation in statistics applies atanh(r) to a correlation coefficient r to stabilize its variance before hypothesis testing. That real-world use is why atanh appears in data science toolchains, not just calculus homework.

Explore C Math Functions

Continue with cbrt() 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.

4 people found this page helpful