--- title: Math.cosh() slug: Web/JavaScript/Reference/Global_Objects/Math/cosh tags: - ECMAScript6 - JavaScript - Math - Méthode - Reference - polyfill translation_of: Web/JavaScript/Reference/Global_Objects/Math/cosh original_slug: Web/JavaScript/Reference/Objets_globaux/Math/cosh ---
La fonction Math.cosh() renvoie le cosinus hyperbolique d'un nombre, défini par :
(Voir la page sur {{jsxref("Objets_globaux/Math/E","e","",1)}})
Math.cosh(x)
xLe cosinus hyperbolique du nombre passé en argument.
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).
Math.cosh()Math.cosh(0); // 1 Math.cosh(1); // 1.5430806348152437 Math.cosh(-1); // 1.5430806348152437
Cette fonction peut être émulée grâce à la fonction {{jsxref("Objets_globaux/Math/exp", "Math.exp()")}} :
Math.cosh = Math.cosh || function(x) {
return (Math.exp(x) + Math.exp(-x)) / 2;
}
On peut également utiliser un unique appel à {{jsxref("Objets_globaux/Math/exp", "exp()")}} :
Math.cosh = Math.cosh || function(x) {
var y = Math.exp(x);
return (y + 1 / y) / 2;
}
| Spécification | État | Commentaires |
|---|---|---|
| {{SpecName('ES6', '#sec-math.cosh', 'Math.cosh')}} | {{Spec2('ES6')}} | Définition initiale. |
| {{SpecName('ESDraft', '#sec-math.cosh', 'Math.cosh')}} | {{Spec2('ESDraft')}} |
{{Compat("javascript.builtins.Math.cosh")}}