Math.cosh()

La fonction Math.cosh() renvoie le cosinus hyperbolique d'un nombre, défini par :

Math.cosh(x) = e x + e - x 2 \mathtt{\operatorname{Math.cosh(x)}} = \frac{e^x + e^{-x}}{2}

Exemple interactif

(Voir la page sur e)

Syntaxe

js
Math.cosh(x);

Paramètres

x

Un nombre.

Valeur de retour

Le cosinus hyperbolique du nombre passé en argument.

Description

cosh() étant une méthode statique de Math, il faut utiliser Math.cosh() et non pas la méthode d'un objet Math créé sur mesure (Math n'est pas un constructeur).

Exemple

Utiliser Math.cosh()

js
Math.cosh(0); // 1
Math.cosh(1); // 1.5430806348152437
Math.cosh(-1); // 1.5430806348152437

Prothèse d'émulation (polyfill)

Cette fonction peut être émulée grâce à la fonction Math.exp() :

js
Math.cosh =
  Math.cosh ||
  function (x) {
    return (Math.exp(x) + Math.exp(-x)) / 2;
  };

On peut également utiliser un unique appel à exp() :

js
Math.cosh =
  Math.cosh ||
  function (x) {
    var y = Math.exp(x);
    return (y + 1 / y) / 2;
  };

Spécifications

Specification
ECMAScript Language Specification
# sec-math.cosh

Compatibilité des navigateurs

BCD tables only load in the browser

Voir aussi