"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/node_modules/es5-ext/math/fround/shim.js" (8 Mar 2017, 666 Bytes) of archive /windows/misc/atom-windows.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Javascript source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    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 };