2
0

shim.js 450 B

1234567891011121314151617
  1. // Parts of implementation taken from es6-shim project
  2. // See: https://github.com/paulmillr/es6-shim/blob/master/es6-shim.js
  3. 'use strict';
  4. var expm1 = require('../expm1')
  5. , abs = Math.abs, exp = Math.exp, e = Math.E;
  6. module.exports = function (x) {
  7. if (isNaN(x)) return NaN;
  8. x = Number(x);
  9. if (x === 0) return x;
  10. if (!isFinite(x)) return x;
  11. if (abs(x) < 1) return (expm1(x) - expm1(-x)) / 2;
  12. return (exp(x - 1) - exp(-x - 1)) * e / 2;
  13. };