[m-dev.] Re: pragma fact_table

David Matthew OVERTON dmo at students.cs.mu.oz.au
Thu Feb 27 16:04:26 AEDT 1997


Fergus Henderson wrote:
> 
> David Matthew OVERTON, you wrote:

[...]

> > +++ float.nu.nl	1997/02/27 02:05:50
> > @@ -49,4 +49,19 @@
> >  
> >  float__epsilon(2.2204460492503131e-16).
> >  
> > +	% Note:  This hash function is different to the one defined in
> > +	% float.m.
> > +float__hash(Float, Hash) :-
> > +	float__abs(Float, Abs),
> > +	( Abs = 0.0 -> Abs2 = 1e-15 ; Abs2 = Abs ),
> > +	math__ln(Abs2, Log),
> > +	math__ceiling(Log, TruncLog),
> > +	math__exp(TruncLog, Pow),
> > +	Float2 is Abs2 / Pow * 2147483647.0,   % 2147483647 = (2^31)-1
> > +	float__truncate_to_int(Float2, N1),
> > +	float__abs(TruncLog, Log2),
> > +	float__truncate_to_int(Log2, N2),
> > +	Hash0 is N1 ^ N2,
> > +	int__abs(Hash0, Hash).
> 
> That code won't work.  (You did test it, didn't you?  Oh.)
> 
> Have a look at the comments at the top of library/math.m.
> 
Oops.  I did check that it compiled with Nu Prolog, but I guess that's
not enough.  Any idea of a reasonable hash function that will work in
Prolog?  I guess it doesn't have to be too fantastic, just something
that will map floats to ints somehow.

[...]

> 
> > #else /* BOXED_FLOAT -- sizeof(Float) > sizeof(Integer) */
> 
> !BOXED_FLOAT implies sizeof(Float) <= sizeof(Integer),
> but BOXED_FLOAT does not imply sizeof(Float) > sizeof(Integer).

Well the comment in runtime/conf.h should be changed then.  This is
what it says:

**      BOXED_FLOAT             double precision floats do not fit in a Word,
**                              and must be boxed.

How can I check that sizeof(Float) > sizeof(Integer) at compile time,
since sizeof() does not work with the #if preprocessor command?  If
this means adding a new parameter to the configure script I've got no
idea how to do this.

> 
> > union FloatInteger {
> > 	Float f;
> > 	Integer i[sizeof(Float)/sizeof(Integer)];
> > };
> > 
> > Integer
> > hash_float(Float f)
> > {
> > 	union FloatInteger fi;
> > 	size_t i;
> > 	Integer h = 0;
> > 
> > 	fi.f = f;
> > 
> > 	for (i = 0; i < sizeof(Float)/sizeof(Integer); i++)
> > 		h ^= fi.i[i];
> 
> This code won't work if sizeof(Float) is not an even multiple of
> sizeof(Integer).
> 
I can't see why it wouldn't work.  It will compute a hash value, it
just won't use all the bits of the float.  How likely is it that
sizeof(Float) is not an even multiple of sizeof(Integer) anyway?

I can use an array of chars instead of Integers if you want (and use
something other than XOR to hash them together).  I just thought this
method would be more efficient.


David.



More information about the developers mailing list