此頁面由社群從英文翻譯而來。了解更多並加入 MDN Web Docs 社群。

View in English Always switch to English

Math.atanh()

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since ⁨2015年7月⁩.

Math.atanh() 靜態方法回傳一個數字的反雙曲正切值,也就是說,

x(1,1),𝙼𝚊𝚝𝚑.𝚊𝚝𝚊𝚗𝚑(𝚡)=artanh(x)=the unique y such that tanh(y)=x=12ln(1+x1x)\begin{aligned}\forall x \in ({-1}, 1),\;\mathtt{\operatorname{Math.atanh}(x)} &= \operatorname{artanh}(x) = \text{the unique } y \text{ such that } \tanh(y) = x \\&= \frac{1}{2}\,\ln\left(\frac{1+x}{1-x}\right)\end{aligned}

嘗試一下

console.log(Math.atanh(-1));
// 預期輸出:-Infinity

console.log(Math.atanh(0));
// 預期輸出:0

console.log(Math.atanh(0.5));
// 預期輸出:0.549306144334055 (approximately)

console.log(Math.atanh(1));
// 預期輸出: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

規範

Specification
ECMAScript® 2026 Language Specification
# sec-math.atanh

瀏覽器相容性

參見