Skip to content
This repository has been archived by the owner on Dec 14, 2021. It is now read-only.

IEEE754 conversion does not match the native #82

Closed
zloirock opened this issue Dec 11, 2015 · 3 comments
Closed

IEEE754 conversion does not match the native #82

zloirock opened this issue Dec 11, 2015 · 3 comments

Comments

@zloirock
Copy link

Currently, I write Typed Arrays polyfill for core-js, but I'm not an expert in IEEE754, so, at first, I tried to explore available functions for IEEE754 conversions. I tried your functions, but packing 32-bit float here does not match the native. For example:

// native:
new Float32Array([2147483647]); // => [2147483648]
new Uint8Array(new Float32Array([2147483647]).buffer); // => [0, 0, 0, 79]
// your:
new Float32Array([2147483647]); // => [2147483904]
new Uint8Array(new Float32Array([2147483647]).buffer); // => [1, 0, 0, 79]

Conversions from this library works fine, but writing my test case still in progress.

@inexorabletash
Copy link
Owner

Ugh, thanks. This looks like one of those "how did it ever work?" cases, but I also haven't revisited all of the code. Can you give this change a whirl with your test cases?

         if (f / pow(2, fbits) >= 2) {
           e = e + 1;
-          f = 1;
+          f = pow(2, fbits);
         }

@zloirock
Copy link
Author

Yep, current test case passed, but, as I said, it's still not finished :)

@inexorabletash
Copy link
Owner

"closed" but I welcome more test cases!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants