Are there denormalized floats that evaluate to the same value apart from +0/-0?

121 views Asked by At

Hashing floats
I want to feel floats (singles, doubles etc) to a hash function.
I want the hash function to generate the same hashes for things which are really the same, but have a different binary representation.

Thus +0/-0 should be normalized.
The many NaN's should be merged into a single representation.
Same for +Inf (which is different from -Inf), etc.

Question
Apart from +0/-0, are there denormalized floats, which really translate to the same discrete value, or can I just hash their binary representation as is, without fear of generating different hashes for identical values?

Bonus question: if there are, what is the fastest way to convalescence these denormals into a unique representation other than using frexp?
(Answer preferably in X64 SSE2 assembly, however C is also OK).

For performance reasons I want to do as little prep work as possible before feeding my floats to the hash. I don't care about compatibility.

1

There are 1 answers

2
Pascal Cuoq On BEST ANSWER

Apart from +0/-0, are there denormalized floats, which really translate to the same discrete value, or can I just hash their binary representation as is, without fear of generating different hashes for identical values?

There is no translation from the representation to something else that would be the “real” value. There is only IEEE 754 equality, which is an equivalence relation but makes some values with differing representations equal. +0.0 and -0.0 are the only floating-point values with differing representations that are equal.

You don't need to do anything special with the many representations of NaN, all NaNs are different (for IEEE 754 equality), even when they have the same representation. Thus NaNs do not need to have the same hash. The same representation of NaN doesn't even need to have the same hash as itself.