]> git.r.bdr.sh - rbdr/dotfiles/blob - atom/packages/vim-mode/node_modules/grim/node_modules/emissary/node_modules/es6-weak-map/node_modules/es5-ext/math/fround/shim.js
f2c86e46a41c7af73e8e6b9923fff03a81ef7b67
[rbdr/dotfiles] / atom / packages / vim-mode / node_modules / grim / node_modules / emissary / node_modules / es6-weak-map / node_modules / es5-ext / math / fround / shim.js
1 // Credit: https://github.com/paulmillr/es6-shim/blob/master/es6-shim.js
2
3 'use strict';
4
5 var toFloat32;
6
7 if (typeof Float32Array !== 'undefined') {
8 toFloat32 = (function () {
9 var float32Array = new Float32Array(1);
10 return function (x) {
11 float32Array[0] = x;
12 return float32Array[0];
13 };
14 }());
15 } else {
16 toFloat32 = (function () {
17 var pack = require('../_pack-ieee754')
18 , unpack = require('../_unpack-ieee754');
19
20 return function (x) {
21 return unpack(pack(x, 8, 23), 8, 23);
22 };
23 }());
24 }
25
26 module.exports = function (x) {
27 if (isNaN(x)) return NaN;
28 x = Number(x);
29 if (x === 0) return x;
30 if (!isFinite(x)) return x;
31
32 return toFloat32(x);
33 };