Converting Int to Float or Float to Int using Bitwise operations (software floating point)

First, a paper you should consider reading, if you want to understand floating point foibles better: “What Every Computer Scientist Should Know About Floating Point Arithmetic,” http://www.validlab.com/goldberg/paper.pdf And now to some meat. The following code is bare bones, and attempts to produce an IEEE-754 single precision float from an unsigned int in the range 0 … Read more

Extracting the exponent and mantissa of a Javascript Number

Using the new ArrayBuffer access arrays, it is actually possible to retrieve the exact mantissa and exponent, by extracting them from the Uint8Array. If you need more speed, consider reusing the Float64Array. function getNumberParts(x) { var float = new Float64Array(1), bytes = new Uint8Array(float.buffer); float[0] = x; var sign = bytes[7] >> 7, exponent = … Read more