acosh
Returns the inverse hyperbolic cosine of a number, the value whose hyperbolic cosine is that number.
acosh(float $num): float- Added in PHP 4.1.0
Parameters
| Parameter | Type | Description |
|---|---|---|
$num | float | The value to process. Must be 1 or greater. |
Return value
floatThe inverse hyperbolic cosine of num. Returns NAN when num is less than 1.
Errors
Throws a TypeError if num cannot be coerced to float. Values below 1 return NAN instead of throwing.
acosh() is the inverse of cosh(): given a hyperbolic cosine it returns the hyperbolic angle that produced it. Mathematically it equals log($num + sqrt($num ** 2 - 1)), but the built-in is more accurate near 1 where that expression loses precision.
When to reach for it
Hyperbolic functions describe hanging cables and arches: a chain suspended between two points follows a cosh curve, so acosh() is how you go from a measured sag back to the parameter of the catenary. It also shows up in special relativity (rapidity from a Lorentz factor), in solving quadratics that arise from exponential growth models, and anywhere a closed-form inverse of cosh is needed instead of an iterative solver.
What trips people up
The domain starts at 1, not at 0 and not at -1. cosh never dips below 1, so anything smaller has no inverse and acosh() returns NAN silently. This bites when a value that should be exactly 1 arrives as 0.9999999999999999 after arithmetic — clamp with max(1.0, $x).
The result is always non-negative. cosh is symmetric, so both +t and -t map to the same value; acosh() returns only the positive branch, and you must supply the sign from context yourself.
Example
When to use it
- Recover the catenary parameter of a hanging cable from its measured sag.
- Convert a Lorentz factor into rapidity in a physics calculation.
- Invert a cosh-based easing or growth curve to find the input that produced a given output.
Frequently asked questions
Why does acosh() return NAN for values less than 1?
Because cosh() never produces a result below 1, so there is no hyperbolic angle whose cosine is smaller than 1. PHP signals that with NAN rather than an error.
Is acosh() the same as 1/acos()?
No. acosh() is the inverse of the hyperbolic cosine, while acos() is the inverse of the circular cosine; neither is the reciprocal of the other. The reciprocal of a cosine is the secant, which is a different idea again.
Can acosh() return a negative number?
No. cosh() is symmetric about zero, so acosh() returns only the non-negative branch. If your model needs the negative solution, negate the result yourself based on context.
More examples
Round trip through cosh()
Each line shows a hyperbolic angle, its hyperbolic cosine, and that cosine fed back through acosh(). The recovered angle matches the original every time, which is what "inverse function" means in practice.
<?php
foreach ([0.0, 0.5, 2.0, 4.0] as $t) {
$c = cosh($t);
printf("t=%.1f cosh=%.6f acosh=%.6f\n", $t, $c, acosh($c));
}Guarding the domain
The near-1 value falls just outside the domain, so acosh() returns float(NAN) and is_nan() confirms it. Clamping the argument to a minimum of 1.0 gives 0, the correct answer.
<?php
$ratio = 0.9999999999999999; // should have been exactly 1.0
var_dump(acosh($ratio));
var_dump(is_nan(acosh($ratio)));
echo acosh(max(1.0, $ratio)), PHP_EOL;
Discussion