--- title: Math.tanh() slug: Web/JavaScript/Referencia/Objectes_globals/Math/tanh translation_of: Web/JavaScript/Reference/Global_Objects/Math/tanh ---
La funció Math.tanh()
retorna la tangent hiperbòlica d'un nombre, és a dir
Math.tanh(x)
x
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).
Math.tanh()
Math.tanh(0); // 0 Math.tanh(Infinity); // 1 Math.tanh(1); // 0.7615941559557649
Aquest comportament pot emular-se amb l'ajuda de la funció {{jsxref("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 {{jsxref("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); } }
Especificació | Estat | Comentaris |
---|---|---|
{{SpecName('ES6', '#sec-math.tanh', 'Math.tanh')}} | {{Spec2('ES6')}} | Definició inicial. |
Característica | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Suport bàsic | {{CompatChrome("38")}} | {{CompatGeckoDesktop("25")}} | {{CompatNo}} | {{CompatOpera("25")}} | {{CompatSafari("7.1")}} |
Característica | Android | Chrome for Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|
Suport bàsic | {{CompatNo}} | {{CompatNo}} | {{CompatGeckoMobile("25")}} | {{CompatNo}} | {{CompatNo}} | 8 |