Math.cosh()

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

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

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

Exemple interactif

console.log(Math.cosh(0));
// Expected output: 1

console.log(Math.cosh(1));
// Expected output: 1.543080634815244 (approximately)

console.log(Math.cosh(-1));
// Expected output: 1.543080634815244 (approximately)

console.log(Math.cosh(2));
// Expected output: 3.7621956910836314

(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® 2025 Language Specification
# sec-math.cosh

Compatibilité des navigateurs

Report problems with this compatibility data on GitHub
desktopmobileserver
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
Node.js
cosh

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

Voir aussi