--- title: Math.cosh() slug: Web/JavaScript/Reference/Global_Objects/Math/cosh translation_of: Web/JavaScript/Reference/Global_Objects/Math/cosh ---
Math.cosh()
函数返回数值的双曲余弦函数, 可用 {{jsxref("Math.E", "constant e", "", 1)}} 表示:
Math.cosh(x)
x
由于cosh()
是Math的静态函数, 只需通过Math.cosh()
调用,而不用通过创建Math对象来调用.
Math.cosh()
Math.cosh(0); // 1 Math.cosh(1); // 1.5430806348152437 Math.cosh(-1); // 1.5430806348152437
可通过 {{jsxref("Math.exp()")}} 函数模拟实现:
Math.cosh = Math.cosh || function(x) { return (Math.exp(x) + Math.exp(-x)) / 2; }
或只调用一次 {{jsxref("Math.exp()")}} 函数:
Math.cosh = Math.cosh || function(x) { var y = Math.exp(x); return (y + 1 / y) / 2; };
Specification | Status | Comment |
---|---|---|
{{SpecName('ES6', '#sec-math.cosh', 'Math.cosh')}} | {{Spec2('ES6')}} | Initial definition. |