IEEE754 bit twiddling back

(L) [2006/09/02] [tbp] [IEEE754 bit twiddling] Wayback!

Burried in another thread was a discussion of radix sort and how to properly tweak an IEEE 754 single precision float into something looking like a lexicographically ordered integer (vague wording intented). Note that radix sorting is not the only use for such a stunt.

On little endian machines that means flipping mantissa & exponent of negative floats.

With the usually prescribed code, compilers would produce something like - Intel syntax, float in edx:
(L) [2006/09/07] [tbp] [IEEE754 bit twiddling] Wayback!

Sadly, it's next to impossible to decently express that solution in C/C++... or with Microsoft silly inline asm.

Here's a drop-in variant, bias the result if you expect unsigned arithmetic.

back