Math.tanh()
La funció Math.tanh()
retorna la tangent hiperbòlica d'un nombre, és a dir
Sintaxi
Math.tanh(x)
Paràmetres
x
- Un nombre.
Descripció
Com que que tanh()
és un mètode estàtic de Math
, sempre s'utilitza com a Math.tanh()
, en comptes de com a mètode d'una instància de Math
(Math
no és un constructor).
Exemples
Utilitzar Math.tanh()
Math.tanh(0); // 0
Math.tanh(Infinity); // 1
Math.tanh(1); // 0.7615941559557649
Polyfill
Aquest comportament pot emular-se amb l'ajuda de la funció Math.exp()
:
Math.tanh = Math.tanh || function(x) {
if (x === Infinity) {
return 1;
} else if (x === -Infinity) {
return -1;
} else {
return (Math.exp(x) - Math.exp(-x)) / (Math.exp(x) + Math.exp(-x));
}
}
o bé utilitzant només una crida a Math.exp()
:
Math.tanh = Math.tanh || 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);
}
}
Especificacions
Especificació | Estat | Comentaris |
---|---|---|
ECMAScript 2015 (6th Edition, ECMA-262) The definition of 'Math.tanh' in that specification. |
Standard | Definició inicial. |
Compatibilitat amb navegadors
We're converting our compatibility data into a machine-readable JSON format.
This compatibility table still uses the old format,
because we haven't yet converted the data it contains.
Find out how you can help! (en-US)
Característica | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Suport bàsic | 38 | 25 (25) | No support | 25 | 7.1 |
Característica | Android | Chrome for Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|
Suport bàsic | No support | No support | 25.0 (25) | No support | No support | 8 |