1
0

shim.js 666 B

123456789101112131415161718192021222324252627282930313233
  1. // Credit: https://github.com/paulmillr/es6-shim/blob/master/es6-shim.js
  2. 'use strict';
  3. var toFloat32;
  4. if (typeof Float32Array !== 'undefined') {
  5. toFloat32 = (function () {
  6. var float32Array = new Float32Array(1);
  7. return function (x) {
  8. float32Array[0] = x;
  9. return float32Array[0];
  10. };
  11. }());
  12. } else {
  13. toFloat32 = (function () {
  14. var pack = require('../_pack-ieee754')
  15. , unpack = require('../_unpack-ieee754');
  16. return function (x) {
  17. return unpack(pack(x, 8, 23), 8, 23);
  18. };
  19. }());
  20. }
  21. module.exports = function (x) {
  22. if (isNaN(x)) return NaN;
  23. x = Number(x);
  24. if (x === 0) return x;
  25. if (!isFinite(x)) return x;
  26. return toFloat32(x);
  27. };