Reference · Math

math.cosh

signature
math.cosh(num) -> float

What it does

The hyperbolic cosine of a number, as a float, as Python's math.cosh: (e^x + e^-x) / 2. It is 1 at zero and at least 1 everywhere, and grows like math.exp, so a large number overflows. Its inverse is math.acosh.

Examples

print(math.cosh(0), math.cosh(1), math.cosh(-1))print(math.cosh(2), math.acosh(math.cosh(2)))
output
1.0 1.5430806348152437 1.54308063481524373.7621956910836314 2.0

Edge cases

print(math.cosh(-2) == math.cosh(2), math.cosh(0.001) >= 1)print(math.isfinite(math.cosh(710)), math.isfinite(math.cosh(-710)))print(math.cosh(math.inf), math.cosh(-math.inf), math.cosh(math.nan))
output
true truetrue trueinf inf NaN

Errors

A result past the largest float is a runtime error (a range error), not an error value: it stops the request, and ?? does not catch it. A value that is not a number is a runtime error too.

this one fails
print(math.cosh(711))
output
line 1: `math.cosh`: math range error (711)
this one fails
print(math.cosh(null))
output
line 1: `math.cosh` expects a number as argument 1, got null

Chaining

The shape of a hanging chain is a * cosh(x / a):

let a = 2print(1 | math.cosh)print([-2, 0, 2] | map((x) => a * math.cosh(x / a)))
output
1.5430806348152437[3.0861612696304874, 2.0, 3.0861612696304874]

See also

math.sinh, math.tanh, math.acosh, math.exp, math.cos

Thread
9Useful? Like it, or add to its thread below.

Thread 0 posts

On math.cosh(): questions, tips, corrections, and code that uses it.

No posts yet. The first one opens the thread.

    Edit this page on GitHub · every example's output was made by running it (tools/refcheck.mjs) · questions on Discord or r/quillo