how to write hash function for double

Thomas Wang thomasw at hpcupt1.cup.hp.com
Wed Jun 19 05:07:22 AEST 1991


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.

The question is whether there can be two different bit patterns of double
that represented the same double number?

double a;
double b;

...

if ((a == b) && (memcmp(&a, &b, sizeof(double)) != 0))
{
   printf("help!\n"); /* can this ever happen in Ansi-C ? */
}


 -Thomas Wang
              (Everything is an object.)
                                                     wang at hpdmsjlm.cup.hp.com
                                                     thomasw at hpcupt1.cup.hp.com



More information about the Comp.lang.c mailing list