atanh()
Today, we will discuss the atanh() function in PHP. This function is used to get the inverse hyperbolic tangent of a number.
The atanh() function in PHP returns the inverse hyperbolic tangent of a number — that is, the value whose hyperbolic tangent (tanh()) equals the given input. It is the exact inverse of tanh(), so tanh(atanh($x)) returns $x for any valid $x.
This page covers the function's syntax and return value, a runnable example with its output, how the domain boundaries behave (-1, 1, and out-of-range inputs), and where the function is actually useful.
Syntax
atanh(float $num): float$num— a number in the range-1 < $num < 1.- Return value — the inverse hyperbolic tangent of
$num, as afloat(in radians).
atanh() has been available since PHP 4.1.0.
How to Use the atanh() Function
You call atanh() with a single numeric argument and it returns the result as a float:
Here we store 0.5 in $number, pass it to atanh(), and print the returned float. Because atanh() is the inverse of tanh(), feeding the result back through tanh() gives the original value:
<?php
echo atanh(0.5), PHP_EOL; // 0.54930614433405
echo tanh(atanh(0.5)), PHP_EOL; // 0.5 (round-trip back to the input)
?>The Domain: Valid Inputs
atanh() is only defined mathematically for inputs strictly between -1 and 1. PHP handles the boundaries and out-of-range values like this:
<?php
echo atanh(0), PHP_EOL; // 0
echo atanh(1), PHP_EOL; // INF (the curve goes to +infinity at 1)
echo atanh(-1), PHP_EOL; // -INF (and -infinity at -1)
var_dump(atanh(2)); // float(NAN) — outside the domain
?>| Input | Result |
|---|---|
-1 < x < 1 | a finite float |
1 | INF |
-1 | -INF |
x > 1 or x < -1 | NAN (not a number) |
When a value might fall outside the domain, guard against it before calling atanh(), or check the result with is_nan() / is_infinite() so an invalid input does not silently propagate NAN through later calculations.
When Would I Use atanh()?
The inverse hyperbolic tangent shows up in statistics, physics, and machine learning:
- Fisher z-transformation in statistics uses
atanh()on correlation coefficients to make their sampling distribution closer to normal. - Special relativity uses it to convert a velocity ratio (
v/c) into rapidity. - Activation functions and gradient math in numerical and ML code.
For the other hyperbolic and inverse-hyperbolic functions, see tanh(), asinh(), acosh(), sinh(), and cosh(). A full list lives in the PHP Math functions reference.
Conclusion
atanh() returns the inverse hyperbolic tangent of a number, accepting inputs strictly between -1 and 1 and returning a float in radians. Remember the boundary behavior — ±1 yield ±INF and out-of-range values yield NAN — and validate input when it comes from an untrusted source. It is the precise inverse of tanh(), which makes it a reliable tool for statistical transforms, physics calculations, and other hyperbolic-math problems.