4 ms·
While we're here, the article you linked recommends equality comparison w.r.t. "the maximum number of possible floating-point values between the two values". A
by skwosh 11y ago
While we're here, the article you linked recommends equality comparison w.r.t. "the maximum number of possible floating-point values between the two values".
Any idea on how to go about this in JavaScript? The binary representation of the float isn't as easy to come by (compared to C, for example), but I wonder if you couldn't get a decent approximation with Math.log2.
- roryokane 11y agoYou can interact with binary representations of numbers in JavaScript using typed arrays – https://developer.mozilla.org/en-US/docs/Web/JavaScript/Typed_arrays https://developer.mozilla.org/en-US/docs/Web/JavaScript/Type.... For example, you can get an array of the bytes in a number `n` with this: new Uint8Array((new Float64Array([n])).buffer)