shim.js 515 B

123456789101112131415161718
  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
  6. , exp = Math.exp
  7. , e = Math.E;
  8. module.exports = function (value) {
  9. if (isNaN(value)) return NaN;
  10. value = Number(value);
  11. if (value === 0) return value;
  12. if (!isFinite(value)) return value;
  13. if (abs(value) < 1) return (expm1(value) - expm1(-value)) / 2;
  14. return (exp(value - 1) - exp(-value - 1)) * e / 2;
  15. };