Cette page a été traduite à partir de l'anglais par la communauté. Vous pouvez contribuer en rejoignant la communauté francophone sur MDN Web Docs.

View in English Always switch to English

Math : méthode statique tanh()

Baseline Large disponibilité

Cette fonctionnalité est bien établie et fonctionne sur de nombreux appareils et versions de navigateurs. Elle est disponible sur tous les navigateurs depuis juillet 2015.

La méthode statique Math.tanh() retourne la tangente hyperbolique d'un nombre. Autrement dit,

𝙼𝚊𝚝𝚑.𝚝𝚊𝚗𝚑(𝚡)=tanh(x)=sinh(x)cosh(x)=exexex+ex=e2x1e2x+1\mathtt{\operatorname{Math.tanh}(x)} = \tanh(x) = \frac{\sinh(x)}{\cosh(x)} = \frac{\mathrm{e}^x - \mathrm{e}^{-x}}{\mathrm{e}^x + \mathrm{e}^{-x}} = \frac{\mathrm{e}^{2x} - 1}{\mathrm{e}^{2x}+1}

Exemple interactif

console.log(Math.tanh(-1));
// Sortie attendue : -0.7615941559557649

console.log(Math.tanh(0));
// Sortie attendue : 0

console.log(Math.tanh(Infinity));
// Sortie attendue : 1

console.log(Math.tanh(1));
// Sortie attendue : 0.7615941559557649

Syntaxe

js
Math.tanh(x)

Paramètres

x

Un nombre.

Valeur de retour

La tangente hyperbolique de x.

Description

Puisque tanh() est une méthode statique de Math, elle doit toujours être utilisée avec la syntaxe Math.tanh(), elle ne doit pas être utilisée comme méthode d'un autre objet Math qui a été instancié (Math n'est pas un constructeur).

Exemples

Utiliser Math.tanh()

js
Math.tanh(-Infinity); // -1
Math.tanh(-0); // -0
Math.tanh(0); // 0
Math.tanh(1); // 0.7615941559557649
Math.tanh(Infinity); // 1

Spécifications

Spécification
ECMAScript® 2027 Language Specification
# sec-math.tanh

Compatibilité des navigateurs

Voir aussi