Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!elroy.jpl.nasa.gov!lll-winken!xanth!cs.odu.edu!kremer From: kremer@cs.odu.edu (Lloyd Kremer) Newsgroups: comp.lang.c Subject: Re: how to write hash function for double Message-ID: <1991Jun25.135148.3726@cs.odu.edu> Date: 25 Jun 91 13:51:48 GMT References: <67790003@hpcupt1.cup.hp.com> Sender: news@cs.odu.edu (News File Owner) Organization: Old Dominion University, Norfolk, VA Lines: 35 Nntp-Posting-Host: opium.cs.odu.edu In article <67790003@hpcupt1.cup.hp.com> thomasw@hpcupt1.cup.hp.com (Thomas Wang) writes: > >The question is whether there can be two different bit patterns of double >that represented the same double number? > It would sure help if you specified what architecture you have since that is the place where floating math is implemented. In the PC/Intel world where floating point is performed using an 80x87 chip or software equivalent, doubles are almost universally implemented as IEEE 754 long reals. In this scenario every bit pattern represents a unique number with the following exceptions: 0.0 and -0.0 are different bit patterns, but represent the same mathematical entity (zero). Most compilers convert -0.0 to 0.0 before storing the value, so you're probably OK here. Positive and negative infinity are different patterns, but are mathematically indistinguishable assuming you're using the "projective" model of infinity. Since the 80x87 chips use the projective model by default, this shouldn't be a problem either. NaN (not a number) values can be encoded in many different ways, but if you're throwing NaN's around in a C program you've got big problems already, so don't worry about it. In summary, I think you'll be safe assuming a one-to-one correspondence between reasonable numbers and bit patterns in the Intel world. Lloyd Kremer Hilton Systems, Inc. kremer@cs.odu.edu