Reference · Math
math.cosh
math.cosh(num) -> floatWhat 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)))1.0 1.5430806348152437 1.54308063481524373.7621956910836314 2.0Edge cases
- The function is even:
math.cosh(-x)ismath.cosh(x), and the answer is never below1. 710is about the largest input that fits a float;711is a range error, and so is-711.infand-infboth giveinf;NaNgivesNaN.
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))true truetrue trueinf inf NaNErrors
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.
print(math.cosh(711))line 1: `math.cosh`: math range error (711)print(math.cosh(null))line 1: `math.cosh` expects a number as argument 1, got nullChaining
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)))1.5430806348152437[3.0861612696304874, 2.0, 3.0861612696304874]See also
math.sinh, math.tanh, math.acosh, math.exp, math.cos
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