--- title: Math.tanh() slug: Web/JavaScript/Reference/Global_Objects/Math/tanh translation_of: Web/JavaScript/Reference/Global_Objects/Math/tanh ---
{{JSRef}}

A função Math.tanh()  retorna a tangente hiperbólica de um número, que é:

tanhx=sinhxcoshx=ex-e-xex+e-x=e2x-1e2x+1\tanh x = \frac{\sinh x}{\cosh x} = \frac {e^x - e^{-x}} {e^x + e^{-x}} = \frac{e^{2x} - 1}{e^{2x}+1}

{{EmbedInteractiveExample("pages/js/math-tanh.html")}}

Syntax

Math.tanh(x)

Parameters

x
Um número.

Return value

Uma tangente hiperbólica de um número dado.

Description

Because tanh() is a static method of Math, you always use it as Math.tanh(), rather than as a method of a Math object you created (Math is not a constructor).

Examples

Using Math.tanh()

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

Polyfill

This can be emulated with the help of the {{jsxref("Math.exp()")}} function:

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);
}

Specifications

Specification Status Comment
{{SpecName('ES2015', '#sec-math.tanh', 'Math.tanh')}} {{Spec2('ES2015')}} Initial definition.
{{SpecName('ESDraft', '#sec-math.tanh', 'Math.tanh')}} {{Spec2('ESDraft')}}  

Compatibilidade com navegadores

{{Compat("javascript.builtins.Math.tanh")}}

See also