Core\Math::cosh
Returns the hyperbolic cosine of a number. That is (exp($n) + exp(-$n)) / 2, where exp is Core\Math::exp.
The result is never below 1.0, and it is 1.0 at zero. A negative number gives the same result as the positive one. The result grows very fast. Above about 710, or below about -710, it is too big for a float and becomes INFINITY. NaN (a value that means "not a number") gives NaN.
In plain words: a cable or chain that hangs between two poles makes a curve. That curve is the hyperbolic cosine.
The examples below show a few results, then very large numbers, then how far a cable between two poles hangs down in the middle.
Parameters
$nfloatAny number.
Return value
Returns float. A number of at least 1.0. It is INFINITY when $n is above about 710 or below about -710. NaN gives NaN.
Examples
A few results
<?nvs// Shows the hyperbolic cosine of a few numbers.
// The result at zero is 1. This prints 1.echo Core\Math::cosh(0.0), "\n";
// A negative number gives the same result as the positive one.// Both lines print 1.5430806348152.echo Core\Math::cosh(1.0), "\n";echo Core\Math::cosh(-1.0), "\n";11.54308063481521.5430806348152Very large numbers
<?nvs// Shows how fast the hyperbolic cosine grows.
// This prints 11013.232920103.echo Core\Math::cosh(10.0), "\n";
// At 710 the result is still a number. This prints 1.1169973830809E+308.echo Core\Math::cosh(710.0), "\n";
// At 711 the result is too big for a `float`. This prints INF.echo Core\Math::cosh(711.0), "\n";
// The result is equal to `Core\Math::INFINITY`. This prints yes.echo Core\Math::cosh(-711.0) == Core\Math::INFINITY ? 'yes' : 'no', "\n";11013.2329201031.1169973830809E+308INFyesA hanging cable
<?nvs// Shows how a planning tool finds how far a cable between two poles hangs down in the middle.
class Cable{ // `$tension` is a number for how tight the cable is. A bigger number means a tighter cable. public static function sag(float $span, float $tension): float { float $drop = $tension * (Core\Math::cosh($span / (2.0 * $tension)) - 1.0); return Core\Math::round($drop, { precision: 2 }); }}
// Two poles 100 meters apart. This prints 6.28, so the cable hangs 6.28 meters down.echo Cable::sag(100.0, 200.0), "\n";
// A tighter cable hangs less. This prints 2.5.echo Cable::sag(100.0, 500.0), "\n";6.282.5