Python Glossary Русский

all Python 3Numbers & mathfunction

math.cosh

hyperbolic

The hyperbolic cosine of x: (e**x + e**-x) / 2.

Syntax

math.cosh(...)

It grows exponentially, so somewhere around an argument of 710 the result no longer fits in a float and you get OverflowError (math range error) instead of a number. It shares little with plain cos: cosh is even too, but it never oscillates and never drops below 1.

Examples

import math
print(math.cosh(0))   # → 1.0
print(round(math.cosh(1), 4))   # → 1.5431
print(round(math.cosh(-1), 4))   # → 1.5431
print(round(math.cosh(2) ** 2 - math.sinh(2) ** 2, 4))   # → 1.0
print(math.cosh(1000))   # → OverflowError

See also

Open in the full glossarydocs.python.orgReport an inaccuracy