Can anyone recommend a cheap (inline) hash function for float64 values that does not hash every small integer as 0?
I think this happens in the hashes module because it uses toU32 which ignores the most significant 32 bits of the float64.
Hashing floats is not that trivial. A common problem are rounding errors. Do you want/need identical hash for i.e. (3.0 + 4.0) and (7.0)? If yes, then it may be necessary to mask the less significant bits before applying the hash function. So, before choosing a concrete optimal hash function, it may be necessary to consider the range of your numbers. In the simplest case, it may be enough to do some plain mathematical operation on your numbers before hashing to get what you want, maybe just adding always the same constant.
[EDIT]
and of course, for more information you may ask google, i.e.
http://stackoverflow.com/questions/4238122/hash-function-for-floats
Many Thanks, It didn't occur to me this would be a general problem. The nim library double hash seems even less useful than the alternatives discussed in the reference you gave. Again, thanks.
Jim Wirth