Math.tanh()
La fonction Math.tanh()
renvoie la tangente hyperbolique d'un nombre définie par :
Syntaxe
Math.tanh(x)
Paramètres
x
- Un nombre.
Valeur de retour
La tangente hyperbolique du nombre fourni en argument.
Description
tanh()
est une méthode statique de l'objet Math
, elle doit toujours être utilisée avec la syntaxe Math.tanh()
, elle ne doit pas être utilisée comme une méthode d'un objet Math
qui aurait été instancié (Math
n'est pas une constructeur).
Exemples
Utiliser Math.tanh()
Math.tanh(0); // 0
Math.tanh(Infinity); // 1
Math.tanh(1); // 0.7615941559557649
Prothèse d'émulation (polyfill)
Cette méthode peut être émulée grâce à la fonction Math.exp()
:
Math.tanh = Math.tanh || function(x){
var a = Math.exp(+x), b = Math.exp(-x);
return a == Infinity ? 1 : b == Infinity ? -1 : (a - b) / (a + b);
}
et si on souhaite n'utiliser qu'un seul appel à Math.exp()
:
Math.tanhx = Math.tanhx || function(x) {
if(x === Infinity) {
return 1;
} else if(x === -Infinity) {
return -1;
} else {
var y = Math.exp(2 * x);
return (y - 1) / (y + 1);
}
};
Spécifications
Spécification | État | Commentaires |
---|---|---|
ECMAScript 2015 (6th Edition, ECMA-262) La définition de 'Math.tanh' dans cette spécification. |
Standard | Définition initiale. |
ECMAScript (ECMA-262) La définition de 'Math.tanh' dans cette spécification. |
Standard évolutif |
Compatibilité des navigateurs
BCD tables only load in the browser
Le tableau de compatibilité de cette page a été généré à partir de données structurées. Si vous souhaitez contribuer à ces données, n'hésitez pas à envoyer une pull request sur https://github.com/mdn/browser-compat-data.