es.math.sinh.js 654 B

12345678910111213141516171819202122
  1. var $ = require('../internals/export');
  2. var fails = require('../internals/fails');
  3. var expm1 = require('../internals/math-expm1');
  4. var abs = Math.abs;
  5. var exp = Math.exp;
  6. var E = Math.E;
  7. var FORCED = fails(function () {
  8. // eslint-disable-next-line es/no-math-sinh -- required for testing
  9. return Math.sinh(-2e-17) != -2e-17;
  10. });
  11. // `Math.sinh` method
  12. // https://tc39.es/ecma262/#sec-math.sinh
  13. // V8 near Chromium 38 has a problem with very small numbers
  14. $({ target: 'Math', stat: true, forced: FORCED }, {
  15. sinh: function sinh(x) {
  16. var n = +x;
  17. return abs(n) < 1 ? (expm1(n) - expm1(-n)) / 2 : (exp(n - 1) - exp(-n - 1)) * (E / 2);
  18. }
  19. });