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

浏览器兼容性

另见