es.math.tanh.js 377 B

1234567891011121314
  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 a = expm1(x = +x);
  9. var b = expm1(-x);
  10. return a == Infinity ? 1 : b == Infinity ? -1 : (a - b) / (exp(x) + exp(-x));
  11. }
  12. });