Math.tanh()

Baseline 已廣泛支援

此特性已相當成熟,可在許多裝置和瀏覽器版本上使用。自 ⁨2015 年 7 月⁩以來,各瀏覽器均已提供此特性。

Math.tanh() 靜態方法返回一個數字的雙曲正切值。即,

𝙼𝚊𝚝𝚑.𝚝𝚊𝚗𝚑(𝚡)=tanh(x)=sinh(x)cosh(x)=exexex+ex=e2x1e2x+1\mathtt{\operatorname{Math.tanh}(x)} = \tanh(x) = \frac{\sinh(x)}{\cosh(x)} = \frac{\mathrm{e}^x - \mathrm{e}^{-x}}{\mathrm{e}^x + \mathrm{e}^{-x}} = \frac{\mathrm{e}^{2x} - 1}{\mathrm{e}^{2x}+1}

試一試

console.log(Math.tanh(-1));
// Expected output: -0.7615941559557649

console.log(Math.tanh(0));
// Expected output: 0

console.log(Math.tanh(Infinity));
// Expected output: 1

console.log(Math.tanh(1));
// Expected output: 0.7615941559557649

語法

js
Math.tanh(x)

引數

x

一個數字。

返回值

x 的雙曲正切值。

描述

因為 tanh()Math 的一個靜態方法,所以你總是將其寫作 Math.tanh(),而不是作為你建立的 Math 物件的函式(Math 不是一個建構函式)。

示例

使用 Math.tanh()

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

規範

規範
ECMAScript® 2026 語言規範
# sec-math.tanh

瀏覽器相容性

另見