ANSI, =, hash, Integer, Float

Richard A. O'Keefe ok at cs.otago.ac.nz
Wed Dec 18 23:09:40 UTC 2002


Hans-Martin Mosner <hmm at heeg.de> wrote:
	The problem is not that Floats can't be used for reasonably exact 
	arithmetic, it's that folks tend to believe that numbers such as
	0.1 can be represented exactly.

Yes, but that has NOTHING to do with the problem this thread is about.

	All examples showing how beautiful and powerful Floats really
	are won't help those folks

And are not intended to, merely to point out over and over again
that there isn't any "definition" issue with Float>> =.  The problem
I am concerned with is that 1 = 1.0 but 1 hash ~= 1.0 hash, and that
is a problem with #hash, not a problem with #=.

	they need to understand that Floats are essentially Fractions
	with a denominator that is a power of 2, whereas the things they
	write down are decimal fractions, which just can't be
	represented exactly as binary fractions.

Well, yes.  But that's what textbooks are for.  That's what CS1 and CS2
are for.  (Actually, on my favourite machine of all time, the denominator
was a power of 8.  And while I've not _used_ the machine I have in mind
where the denominator was a power of 10 and the significand could be up
to 99 decimal digits, I've seen one and read the manuals.  There's a reason
why IEEE 854 explicitly defines arithmetic for decimal floats.  And the
student BASIC system written at Auckland University back in the late 70's
had decimal floating-point arithmetic in software, so that 0.1 was _exact_.
Strictly speaking, it's up to the hardware and software whether 0.1 is
exact or not, and if I'm reading the ANSI Smalltalk standard correctly,
the intention is that 0.1s0 (note the 's') should be exact.)

	Perhaps we should add some code to the compiler that warns the
	user whenever he compiles a piece of code with such a number,
	until the user finds the preference named "I understand what
	floats are and won't complain on the mailing list" :-)

This is the only suggestion I've ever seen that actually tackles the
comprehension problem without hampering people who know what they are
doing.  It has two deficiencies:

(1) It's hard to make things fool-proof because fools are so ingenious.
    I remember someone telling me about a statistics package they had
    written which would only let you do meaningful regressions.  Instead
    of being glad to have errors caught before it was too late, their
    users had discovered that they could save data to a file and load it
    back in as if it was completely new data, thereby tricking the
    program into accepting calculations which made no sense.

    In this case, if writing 0.1 provokes a warning message, people
    are likely to hack around it by writing 1 asFloat / 10 asFloat,
    leaving the problem intact.

(2) It does nothing to address the "#hash is inconsistent" problem.




More information about the Squeak-dev mailing list