shim.js 330 B

1234567891011121314151617
  1. 'use strict';
  2. var exp = Math.exp;
  3. module.exports = function (x) {
  4. var a, b;
  5. if (isNaN(x)) return NaN;
  6. x = Number(x);
  7. if (x === 0) return x;
  8. if (x === Infinity) return 1;
  9. if (x === -Infinity) return -1;
  10. a = exp(x);
  11. if (a === Infinity) return 1;
  12. b = exp(-x);
  13. if (b === Infinity) return -1;
  14. return (a - b) / (a + b);
  15. };