Math.tanh()
Math.tanh() 静态方法返回一个数字的双曲正切值。即,
试一试
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 |
浏览器兼容性
加载中…