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 July 2015.

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

規範

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

瀏覽器相容性

Report problems with this compatibility data on GitHub
desktopmobileserver
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
Node.js
atanh

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

參見