how to write hash function for double
Lloyd Kremer
kremer at cs.odu.edu
Tue Jun 25 23:51:48 AEST 1991
In article <67790003 at hpcupt1.cup.hp.com> thomasw at 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 at cs.odu.edu
More information about the Comp.lang.c
mailing list