how to write hash function for double
der Mouse
mouse at thunder.mcrcim.mcgill.edu
Wed Jun 26 19:59:58 AEST 1991
In article <67790003 at hpcupt1.cup.hp.com>, thomasw at hpcupt1.cup.hp.com (Thomas Wang) writes:
> I want to write a hash function for C double floating point number.
> I can either convert the double to string, then hash the string
> value. Or I can just scramble the bits contained in the double
> number.
It depends on what properties you want the hash to have, I suppose. Do
you require that two numerically equal numbers must have the same hash
value, or do you need identical hash values only for identical
representations, instead of for identical values?
> The question is whether there can be two different bit patterns of
> double that represented the same double number?
Certainly. On a VAX, for example, any bit-pattern with the sign and
exponent fields full of 0 bits represents an exact 0.0 value. (There
are 2^23 - 8388608 - such bit-patterns. And that's just for
single-float.)
der Mouse
old: mcgill-vision!mouse
new: mouse at larry.mcrcim.mcgill.edu
More information about the Comp.lang.c
mailing list