--- title: Math.tanh() slug: Web/JavaScript/Reference/Global_Objects/Math/tanh tags: - ECMAScript6 - JavaScript - Math - Method - tanh - 双曲正切 translation_of: Web/JavaScript/Reference/Global_Objects/Math/tanh ---
Math.tanh()
函数将会返回一个数的双曲正切函数值,公式如下:
Math.tanh(x)
x
所给数字的双曲正切值。
因为 tanh()
是 Math
的静态方法,所以总应该直接调用 Math.tanh()
,而不是创建 Math
对象再调用该方法(Math
不是一个构造函数)。
Math.tanh()
Math.tanh(0); // 0 Math.tanh(Infinity); // 1 Math.tanh(1); // 0.7615941559557649
tanh()
可以通过 {{jsxref("Math.exp()")}} 函数实现:
Math.tanh = Math.tanh || function(x){ var a = Math.exp(+x), b = Math.exp(-x); return a == Infinity ? 1 : b == Infinity ? -1 : (a - b) / (a + b); }
规范 |
---|
{{SpecName('ESDraft', '#sec-math.tanh', 'Math.tanh')}} |
The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
{{Compat("javascript.builtins.Math.tanh")}}