Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!sdd.hp.com!hplabs!hpda!hpcupt1!thomasw From: thomasw@hpcupt1.cup.hp.com (Thomas Wang) Newsgroups: comp.lang.c Subject: how to write hash function for double Message-ID: <67790003@hpcupt1.cup.hp.com> Date: 18 Jun 91 19:07:22 GMT Organization: Hewlett Packard, Cupertino Lines: 23 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@hpdmsjlm.cup.hp.com thomasw@hpcupt1.cup.hp.com