Last active
September 1, 2018 04:00
-
-
Save westc/b2cf4654d579575da6c929622edfc499 to your computer and use it in GitHub Desktop.
YourJS candidate function: fround()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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
https://www.yourjs.com/console/?gist=b2cf4654d579575da6c929622edfc499&file=fround.js