ANSI, =, hash, Integer, Float
Hans-Martin Mosner
hmm at heeg.de
Wed Dec 18 11:38:07 UTC 2002
Richard A. O'Keefe wrote:
>Bryce Kampjes <bryce at kampjes.demon.co.uk> asks:
> Given the "Floating Point" discussion, is it possible that
> Floats shouldn't be used as keys in collections?
>
>A core property of 'reasonable' floating-point systems
>is that there is a wide range of numbers for which floating-point
>arithmetic is EXACT. I'm defining 'reasonable' here to mean
>'can be described by the Brown model with parameters that are
>not so outrageous the designer should have died of shame';
>pretty much anything you are likely to meet these days (and I
>am including AS/400 and z/Architecture in the list) counts as
>reasonable.
>
>
>
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. All examples showing how beautiful and powerful
Floats really are won't help those folks - 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.
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" :-)
Cheers,
Hans-Martin
More information about the Squeak-dev
mailing list
|