Skip to content
Tutorials Center
My learning

Topics

JavaScript Reference Β· Math

Math.sinh(), Math.cosh() and Math.tanh()

Reference for Math.sinh(), cosh() and tanh(), plus asinh, acosh and atanh: definitions via exp(), ranges, the tanh activation and the catenary curve.

The hyperbolic functions Math.sinh(), Math.cosh() and Math.tanh() are cousins of sine, cosine and tangent, but they are built from the exponential function instead of a circle. They are defined as sinh(x) = (e^x - e^-x) / 2, cosh(x) = (e^x + e^-x) / 2 and tanh(x) = sinh(x) / cosh(x).

You will meet them in physics (a hanging chain forms a catenary, described by cosh), in special relativity, and in machine learning, where tanh is a classic activation function that squashes any number into the range -1 to 1.

JavaScript
Math.sinh(x)
Math.cosh(x)
Math.tanh(x)

Try it

JS Values and ranges

Press Run (or Ctrl + Enter) to see the console output here.

No output.

JS From exp, and a catenary

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Syntax

JavaScript
Math.sinh(x)
Math.cosh(x)
Math.tanh(x)

Math.asinh(x)
Math.acosh(x)
Math.atanh(x)
Name Description
x A number (or a value that converts to one). Not an angle: hyperbolic functions are not periodic.

Return value: sinh() returns any real number, cosh() returns a number >= 1, and tanh() returns a number from -1 to 1. The inverse functions are asinh() (any input), acosh() (input >= 1, else NaN) and atanh() (input from -1 to 1; Β±1 gives Β±Infinity).

Exceptions: a BigInt argument throws a TypeError.

Usage notes

  • Not about angles. Do not convert degrees to radians for these functions.
  • Overflow. Math.sinh() and Math.cosh() become Infinity once x is beyond roughly 710 in size. Math.tanh() is safe for large inputs and returns exactly 1 or -1.
  • Prefer the built-ins to hand-written Math.exp() formulas: they stay accurate for small x, where the exponential difference exp(x) - exp(-x) loses digits.
  • Symmetry. cosh() is even, sinh() and tanh() are odd.
  • Neural networks. tanh is zero-centered, unlike the sigmoid, but saturates for large inputs.
  • Other uses: the shape of a hanging cable, wave speeds in water, and rapidity in relativity.

Browser support

All six methods are part of ES2015 and supported in all current browsers.