Skip to content

Core\Math::acosh

Returns the number whose hyperbolic cosine is the number you give it. This is the inverse hyperbolic cosine, and it undoes Core\Math::cosh.

The number must be 1.0 or more, because a hyperbolic cosine is never smaller than 1.0. The result is 0.0 or more. A number below 1.0 gives NaN (a value that means "not a number"), and Core\Math::isNan tests for it.

In plain words: a cable that hangs between two poles has the shape of a cosh curve. acosh works the other way. From the height of a point on the cable, it finds how far that point is from the lowest point.

The examples below show a few results, then what happens below 1.0, then how far apart two poles can stand when a cable may sag a given amount.

Parameters

  • $nfloatA hyperbolic cosine: a number that is 1.0 or more.

Return value

Returns float. A number that is 0.0 or more. A $n below 1.0 gives NaN.

Examples

Undoing cosh

<?nvs
// Shows what `Core\Math::acosh` returns for a few numbers, and that it undoes `Core\Math::cosh`.
// 1.0 is the smallest hyperbolic cosine, and it belongs to 0. This prints 0.
echo Core\Math::acosh(1.0), "\n";
// This prints 1.3169578969248.
echo Core\Math::acosh(2.0), "\n";
// `Core\Math::cosh` of 3.0 is about 10.07. `acosh` of that number is 3 again.
// This prints 3.
echo Core\Math::acosh(Core\Math::cosh(3.0)), "\n";
Output
0
1.3169578969248
3

A number below one

<?nvs
// Shows what `Core\Math::acosh` returns for a number below 1.0, and how to keep a
// calculated number in range.
// No number has a hyperbolic cosine of 0.5, so the result is `NaN`. This prints NAN.
echo Core\Math::acosh(0.5), "\n";
// `Core\Math::isNan` tests for that result. This prints "no result".
echo Core\Math::isNan(Core\Math::acosh(0.5)) ? 'no result' : 'a result', "\n";
// A calculation can end a tiny bit below 1.0 because of rounding.
float $ratio = 0.9999999999999999;
// `Core\Math::max` moves it back to 1.0 first. This prints 0.
echo Core\Math::acosh(Core\Math::max($ratio, 1.0)), "\n";
Output
NAN
no result
0

How far apart two poles can stand

<?nvs
// Shows how an app that plans power lines finds how far apart two poles can stand.
// The cable between them may sag a given number of metres.
// A hanging cable has the shape of a `cosh` curve. `acosh` turns the sag into a distance.
class Span
{
// `$tension` says how tight the cable is. A bigger number means a tighter cable.
public static function width(float $tension, float $sag): float
{
float $half = $tension * Core\Math::acosh(($tension + $sag) / $tension);
return Core\Math::round($half * 2.0, { precision: 1 });
}
}
// A tight cable that may sag 5 metres. This prints 63.
echo Span::width(100.0, 5.0), "\n";
// The same cable may sag 10 metres. This prints 88.7.
echo Span::width(100.0, 10.0), "\n";
// A looser cable that may sag 5 metres. The poles must be closer. This prints 44.4.
echo Span::width(50.0, 5.0), "\n";
Output
63
88.7
44.4