C atanh() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
math.h

Definition

In C, atanh() returns the inverse hyperbolic tangent of x. atanh(0) is 0. A negative input gives a negative result.

You pass one double. It must be greater than -1 and less than 1. The result is a double. Include <math.h>.

Syntax

Pass a value strictly between -1 and 1. Start with this call.

C
atanh(0.0);
CallWhat it does
atanh(0.0)Returns 0.

Include <math.h>. On GCC, link with -lm.

Library declarations
C
double atanh(double x);
float atanhf(float x);
long double atanhl(long double x);

Parameters

ParameterDescription
xRequired. A double greater than -1 and less than 1.

Return Value

Return ValueDescription
Inverse hyperbolic tangentA double with the same sign as x.
NaNReturned when x is outside the open range from -1 to 1.

C Examples

Example 1 — Common atanh Values

Print results for zero and a pair of opposite inputs.

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

int main(void) {
    printf("atanh(0)    = %.4f\n", atanh(0.0));
    printf("atanh(0.5)  = %.4f\n", atanh(0.5));
    printf("atanh(-0.5) = %.4f\n", atanh(-0.5));

    return 0;
}

How It Works

  1. Include math.h. Declares atanh; link with -lm on GCC.
  2. Zero maps to zero. atanh(0) is 0.
  3. Positive half. atanh(0.5) ≈ 0.5493.
  4. Odd function. atanh(-0.5) is the negative of atanh(0.5).

Example 2 — Check with tanh

Round-trip a value: tanh(atanh(x)) should recover x on the valid domain.

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

int main(void) {
    double x = 0.75;
    double t = atanh(x);

    printf("atanh(%.2f) = %.5f\n", x, t);
    printf("tanh(t)     = %.5f\n", tanh(t));

    return 0;
}

How It Works

  1. Start in domain. 0.75 satisfies |x| < 1.
  2. Invert with atanh. You get a real t.
  3. Apply tanh. tanh(t) returns to 0.75.
  4. Inverse pair. Use this to verify your understanding of atanh and tanh.

Example 3 — Guard the Domain

Reject |x| ≥ 1 before calling atanh so you do not print a quiet NaN by surprise.

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

int main(void) {
    double x = 1.0;

    if (x <= -1.0 || x >= 1.0) {
        printf("x out of domain for atanh\n");
    } else {
        printf("atanh(%.1f) = %.4f\n", x, atanh(x));
    }

    return 0;
}

How It Works

  1. Endpoints are invalid. atanh(1) and atanh(-1) are not defined as real numbers.
  2. Check before the call. Compare against -1 and 1.
  3. Avoid silent NaN. A clear message is easier to debug than nan in output.
  4. Library may set errno. See errno / EDOM for domain errors if you call anyway.

Frequently Asked Questions

atanh() returns the inverse hyperbolic tangent of x. atanh(0) is 0.
x is required. It must be greater than -1 and less than 1.
A double with the same sign as x. Outside the open range from -1 to 1, the result is not a normal finite number.
Include <math.h>. On GCC, link with -lm.
No. Those values are outside the open domain.

Next: cbrt()

Compute the real cube root of a floating-point value.

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