Skip to content

Instantly share code, notes, and snippets.

@westc
Last active September 1, 2018 04:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save westc/b2cf4654d579575da6c929622edfc499 to your computer and use it in GitHub Desktop.
Save westc/b2cf4654d579575da6c929622edfc499 to your computer and use it in GitHub Desktop.
YourJS candidate function: fround()
// Not available in IE.
//
var fround;
(function (array) {
fround = function(x) {
return array[0] = x, array[0];
};
})(new Float32Array(1));
//\\
// Examples from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/fround
fround(1.5); // -> 1.5
//\\
fround(1.5) === 1.5; // -> true
//\\
fround(1.337); // -> 1.3370000123977661
//\\
fround(1.337) === 1.337; // -> false
//\\
2 ** 150; // -> 1.42724769270596e+45
//\\
fround(2 ** 150); // -> Infinity
//\\
fround('abc'); // -> NaN
//\\
fround(NaN); // -> NaN
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment