Skip to content

Instantly share code, notes, and snippets.

@mraleph
Created March 24, 2014 11:34
Show Gist options
  • Save mraleph/9738601 to your computer and use it in GitHub Desktop.
Save mraleph/9738601 to your computer and use it in GitHub Desktop.
if (!Math.fround) {
Math.fround = (function() {
var temp = new Float32Array(1);
return function fround(x) {
temp[0] = +x;
return temp[0];
}
})();
}
// No such thing as FEPSILON in the ES6. I just put it on Number for consistency with Number.EPSILON which is ES6
Number.FEPSILON = Number.FEPSILON || 1.192092896e-07;
Math.fround(0.4999999 + Number.FEPSILON)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment