shim.js 282 B

123456789101112131415
  1. 'use strict';
  2. var log = Math.log, sqrt = Math.sqrt;
  3. module.exports = function (x) {
  4. if (isNaN(x)) return NaN;
  5. x = Number(x);
  6. if (x === 0) return x;
  7. if (!isFinite(x)) return x;
  8. if (x < 0) {
  9. x = -x;
  10. return -log(x + sqrt(x * x + 1));
  11. }
  12. return log(x + sqrt(x * x + 1));
  13. };