在数学上等效于(e x -e -x )/(e x + e -x ) 。
Math.tanh()
函数的语法为:
Math.tanh(x)
tanh()
是静态方法,使用Math
类名称进行调用。
Math.tanh()参数
Math.tanh()
函数接受:
- x-一个数字
从Math.tanh()返回值
- 返回给定数字的双曲正切值。
示例:使用Math.tanh()
// Math.tanh(x) is (e**(x) - e**(-x))/(e**(x) + e**(-x))
var num = Math.tanh(0);
console.log(num); // 0
var num = Math.tanh(1);
console.log(num); // 0.7615941559557649
var num = Math.tanh(-1);
console.log(num); // -0.7615941559557649
var num = Math.tanh(2);
console.log(num); // 0.9640275800758169
输出
0
0.7615941559557649
-0.7615941559557649
0.9640275800758169
推荐读物:
- JavaScript数学atanh()
- JavaScript数学sinh()