Reputation: 189656
I have a javascript program (running in jsdb which uses Mozilla Spidermonkey 1.8, not in a browser) that I need to convert float and doubles to/from the appropriate number of bytes of their IEEE representations. Java has Float.floatToIntBits() and Float.intBitsToFloat() and similar methods for Double.
Is there a way to compute these functions in Javascript? (and yes, I know that all javascript numbers are essentially of type double)
I guess I could follow the algorithms in the javadoc for Double.longBitsToDouble() and Float.intBitsToFloat() but that only covers one direction, and I need both.
Upvotes: 3
Views: 2041
Reputation: 3214
As i know, javascript doesn't have such native methods.
Here is some sort of things, you want to have. Please examine the source code: http://babbage.cs.qc.edu/IEEE-754/IEEE-754hex32.html
Upvotes: 1