]> gerrit.simantics Code Review - simantics/district.git/blob - fround/shim.js
Hide "enabled" column for non-component type tech type tables
[simantics/district.git] / 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 };