简体   繁体   中英

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

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM