Python math.atanh() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
math module

Definition

math.atanh(x) returns the inverse hyperbolic tangent of x as a float, undoing math.tanh().

It accepts numbers strictly between -1 and 1 (the open interval (-1, 1)). Passing 1.0, -1.0, or anything beyond them raises ValueError.

math.atanh() is a function in Python's standard math module: import it with import math and call math.atanh(...), or import the name directly with from math import atanh.

Syntax

Import math and pass a value strictly inside (-1, 1).

python
import math

z = math.atanh(r)
CallWhat it does
math.atanh(0)Returns 0.0.
math.atanh(0.5)Returns approximately 0.549306....
math.atanh(1)Raises ValueError: endpoint 1 is excluded.
math.atanh(-1.5)Raises ValueError: outside (-1, 1).

Notice that unlike math.asin() and math.acos() (which allow 1 and -1), math.atanh() excludes both endpoints because atanh(±1) diverges to infinity.

Function signatures
python
math.atanh(x, /)
# returns: float inverse hyperbolic tangent for -1 < x < 1

Parameters

ParameterDescription
xRequired positional number (int or float) strictly greater than -1 and strictly less than 1.

Return Value

Return ValueDescription
floatReal inverse hyperbolic tangent of x; returns -0.0 for -0.0 and nan for nan.

Python Examples

Example 1 — Apply Fisher z-Transform to Correlation Scores

Map correlation coefficients in (-1, 1) onto an unbounded scale using math.atanh(r).

python
import math

for r in [-0.9, -0.5, 0.0, 0.5, 0.9]:
    z = math.atanh(r)
    print(f"r={r:+4.1f} -> z={z:+7.4f}")

How It Works

  1. Direct statistics shortcut. Fisher's z-transform 0.5 * ln((1 + r) / (1 - r)) is mathematically identical to math.atanh(r).
  2. Stretches near ±1. Correlations near 0.9 expand to 1.4722 while small values stay close to r.
  3. Symmetric around zero. Negative and positive correlations mirror each other cleanly.

Example 2 — Verify Round-Trip Inversion With math.tanh()

Confirm math.atanh(math.tanh(z)) recovers z and check math.log1p() equivalence.

python
import math

for z in [-0.7, 0.0, 0.7]:
    recovered = math.atanh(math.tanh(z))
    print(f"{z:+4.1f} -> {recovered:+4.1f} close={math.isclose(recovered, z)}")

How It Works

  1. Clean inverse. Passing math.tanh(0.7) back into math.atanh() recovers 0.7.
  2. Zero untouched. Zero maps cleanly to zero and back.
  3. Exact float check. math.isclose() confirms accuracy within standard relative tolerance.

Example 3 — Guard Against Endpoints +1, -1, and Out-of-Range Values

See ValueError raised at 1.0, -1.0, and 1.5.

python
import math

for bad_r in [-1.0, 1.0, 1.5]:
    try:
        math.atanh(bad_r)
    except ValueError:
        print(f"atanh({bad_r}) raises ValueError")

How It Works

  1. Endpoints excluded. Passing -1.0 or 1.0 raises ValueError instead of returning infinity.
  2. Outside range rejected. Values past one like 1.5 raise the same ValueError.
  3. Clamp before transform. In real pipelines, clamp correlations slightly inside (-1, 1) before calling atanh().

Frequently Asked Questions

Because tanh(y) approaches 1 only in the limit y -> inf, so atanh(1) has no finite real value.
Strictly between -1 and 1 (-1 < x < 1).
Fisher z-transform of correlation r is literally atanh(r), equal to 0.5 * log((1 + r) / (1 - r)) for |r| < 1.
Passing that rounded 1.0 to math.atanh() raises ValueError. Check abs(y) < 1.0 before inverting.
Import cmath and use cmath.atanh(x), which returns a complex number.

Next: math.cbrt()

Return the real cube root of x as a float (Python 3.11+).

cbrt() →

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.

14 people found this page helpful