Sorting floating-point values using their byte-representation
If you want to let Radix sorting stay a stable sorting algorithm, you have to swap all subsections of equal elemts in the negative section once more, because when you swaped the negative numbers, the original stable sorting were in stable order.
Assoc. prof. Arne Maus, Univ of Oslo
Your approach:
I think a simple modification can extend this to negative numbers: XOR all positive numbers with 0x8000... and negative numbers with 0xffff.... This should flip the sign bit on both (so negative numbers go first), and then reverse the ordering on negative numbers. Does anyone see a problem with this?
is definitely the answer. Moreover, it was used, for example, in dBase and clones to organize sorting on a float column, and I guess it's followed by newer DB generations.
Also, it is identical to the "total order" according to IEEE-754 for binary representations. (But not for decimal ones, the latter is much more complex.)
UPDATE: as suggested by @Sneftel: you could find replacing -0 with +0 as useful before converting to bit string.