Math.atanh()

Baseline 已廣泛支援

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

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

x(1,1),𝙼𝚊𝚝𝚑.𝚊𝚝𝚊𝚗𝚑(𝚡)=artanh(x)=唯一y使得tanh(y)=x=12ln(1+x1x)\begin{aligned}\forall x \in ({-1}, 1),\;\mathtt{\operatorname{Math.atanh}(x)} &= \operatorname{artanh}(x) = \text{唯一滿足 } \tanh(y) = x \text{ 的 } y \\&= \frac{1}{2}\,\ln\left(\frac{1+x}{1-x}\right)\end{aligned}

試一試

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

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

console.log(Math.atanh(0.5));
// Expected output: 0.549306144334055 (approximately)

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

語法

js
Math.atanh(x)

引數

x

一個介於 -1 和 1 之間的數字(包含兩端)。

返回值

x 的逆雙曲正切值。如果 x 為 1,則返回 Infinity。如果 x 為 -1,則返回 -Infinity。如果 x 小於 -1 或大於 1,則返回 NaN

描述

由於 atanh()Math 的靜態方法,您總是使用 Math.atanh() 來呼叫它,而不是作為您建立的 Math 物件的(Math 不是建構函式)。

示例

使用 Math.atanh()

js
Math.atanh(-2); // NaN
Math.atanh(-1); // -Infinity
Math.atanh(-0); // -0
Math.atanh(0); // 0
Math.atanh(0.5); // 0.5493061443340548
Math.atanh(1); // Infinity
Math.atanh(2); // NaN

規範

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

瀏覽器相容性

另見