If have an 8-byte section of data and write a double-precision floating-point value to it, under what conditions will comparison by numerical comparison and lexicographic sorting of the bytes agree?
Current theory: positive, big-endian
I believe that if the number is positive, and the representation is big-endian, then numerical ordering of the floating-point values will match the lexicographic ordering of the bytes.
The idea is that it would first sort on the exponent, then on the mantissa. Even the "denormalized" IEEE representation shouldn't cause any problems.
Is this true?
(I'm using Node's Buffer::writeDoubleBE, but that shouldn't matter.)
Follow-up
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?