es.math.tanh.js 388 B

123456789101112131415
  1. var $ = require('../internals/export');
  2. var expm1 = require('../internals/math-expm1');
  3. var exp = Math.exp;
  4. // `Math.tanh` method
  5. // https://tc39.es/ecma262/#sec-math.tanh
  6. $({ target: 'Math', stat: true }, {
  7. tanh: function tanh(x) {
  8. var n = +x;
  9. var a = expm1(n);
  10. var b = expm1(-n);
  11. return a == Infinity ? 1 : b == Infinity ? -1 : (a - b) / (exp(n) + exp(-n));
  12. }
  13. });