Incongruent hash

Eliot & Linda elcm at pacbell.net
Mon Feb 9 00:28:13 UTC 1998


Christopher Oliver wrote:
> 
> > Luciano Notarfancesco told me this bug:
> >
> >     1 = 1.0 true
> > but
> >     1 hash = 1.0 hash false
> 
> I really do not know how to feel about this.  I just read through the
> Purple Book and the draft std, and I understand what you mean.  How-
> ever, this hits me as a problem in types.  The first statement is true
> only by coercion.  Should a programmer really expect hash to be invar-
> iant across coercions between types?

YES!  If 1 = 1.0 then 1 hash _should_ equal 1.0 hash.  Its not trivial
to implement efficiently, but it _is_ possible; look at VisualWorks.  At
least in VisualWorks 3.0
	1 = (Fraction numerator: 1 denominator: 1) = 1.0 = 1.0d
and
	1 hash = (Fraction numerator: 1 denominator: 1) hash = 1.0 hash = 1.0d
hash = 1

> My brief exposure to numerical computation suggests this to be in the
> realm of curiosity rather than a serious matter.  Use of equality where
> floats are concerned is dangerous practice.

Yes, but is that reason to break equality between the integers and the
set of integers exactly representable by floats and doubles?
_______________,,,^..^,,,_______________
Eliot





More information about the Squeak-dev mailing list