I am trying to perform something that is brain-dead simple in any other language but not javascript: get the bits out of float (and the other way around).
In C/C++ it would be something like
float a = 3.1415; int b = *((int*)&a);
and vise-versa
int a = 1000; float b = *((float*)&a);
In C# you can use the BitConverter ...floatBits or something alike in Java... Even in VB6 for Christ's sake you can memcpy a float32 into an int32. How on earth can I translate between and int and a float in javascript?
JavaScript Number Data types JavaScript has only one Number (numeric) data types. Number data type can store normal integer, floating-point values. A floating-point represent a decimal integer with either decimal points or fraction expressed (refer to another decimal number).
The JavaScript Number type is a double-precision 64-bit binary format IEEE 754 value, like double in Java or C#.
"There's no such thing as an integer in JavaScript, so you have to be a little careful with your arithmetic if you're used to math in C or Java."
function DoubleToIEEE(f) { var buf = new ArrayBuffer(8); (new Float64Array(buf))[0] = f; return [ (new Uint32Array(buf))[0] ,(new Uint32Array(buf))[1] ]; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With