# Math.tanh()

Math.tanh() 函数将会返回一个数的双曲正切函数值，公式如下：

$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}$

## 语法

Math.tanh(x)

### 参数

x

## 示例

### 使用 Math.tanh()

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


## 向下兼容

tanh() 可以通过 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);
}

## 规范

ECMAScript (ECMA-262)
Math.tanh

## 浏览器兼容性

Update compatibility data on GitHub
Desktop Mobile Server Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Chrome Full support 38 Edge Full support 12 Firefox Full support 25 IE No support No Opera Full support 25 Safari Full support 8 WebView Android Full support 38 Chrome Android Full support 38 Firefox Android Full support 25 Opera Android Full support 25 Safari iOS Full support 8 Samsung Internet Android Full support 3.0 nodejs Full support 0.12

Full support
Full support
No support
No support