Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!think.com!sdd.hp.com!spool.mu.edu!snorkelwacker.mit.edu!thunder.mcrcim.mcgill.edu!mouse From: mouse@thunder.mcrcim.mcgill.edu (der Mouse) Newsgroups: comp.lang.c Subject: Re: how to write hash function for double Message-ID: <1991Jun26.095958.6495@thunder.mcrcim.mcgill.edu> Date: 26 Jun 91 09:59:58 GMT Article-I.D.: thunder.1991Jun26.095958.6495 References: <67790003@hpcupt1.cup.hp.com> Organization: McGill Research Centre for Intelligent Machines Lines: 25 In article <67790003@hpcupt1.cup.hp.com>, thomasw@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@larry.mcrcim.mcgill.edu