[MLton] real hash table

Matthew Fluet fluet@cs.cornell.edu
Mon, 29 May 2006 17:54:01 -0400 (EDT)


> I have to make a hash table of real values.  For the hash function, it looks
> like the best way is to use PackRealBig and to then compute a hash on the
> Word8Vector.

I think that is the best way, but note that the PackReal* functions all go 
through C functions.

[BTW, what we really need are bitwise coercions between Real64.real and 
Word64.word and Real32.real and Word32.word.  Then the PackReal* 
structures can be implemented using the PackWord* structures.  Also, it 
would be nice to have the coercions for other things: doing sign and class 
functions in ML, rather than via C-functions.]

> The problem is that I need to make sure that the real is in 64-bit mode 
> so that the Real.== comparisons work in the way that I want them to. 
> (Forget, for the moment, about Nan's.)  This seems like a general 
> problem where you compute something and now you want that something in 
> its 64-bit form, not in any extended 80-bit form.  What is the fastest 
> way to do that conversion from within MLton?

You could compile with '-ieee-fp true' (native codegen only); this causes 
every floating point value to be written to memory and read back, 
effectively keeping it at the declared precision.  But, that will slow 
down everything.

If you can really forget about NANs, then you could pair each Real64.real 
in the hash table with a Word64.word, where the word is obtained by 
reading the bits out of the Word8Vector that you used to compute the hash. 
Now you can compare the Word64.word values to get (bitwise) equality of 
their corresponding Real64.real values (at 64-bits).  Of course, you might 
get some numerical artifacts stemming from the fact that the Real64.real 
might be maintained at 80-bits in an FP register.