Floating point
Ned Konz
ned at bike-nomad.com
Tue Dec 17 01:19:27 UTC 2002
On Monday 16 December 2002 07:47 am, bitwAttb wrote:
> Hello,
>
> Executing this in a workspace on my machine returns 'false'
> incorrectly ..
>
> ( ( 1.1 + 1.1 + 1.1) / 3.0) = ( ( 1.1 + 1.1 + 1.1 + 1.1 + 1.1 + 1.1
> ) / 6.0 )
>
> The inspector suggests a discrepancy in the LSB of field '2' of the
> floats. I got the same error in 3.2-4956 image and in 3.4B. An
> Athlon 900. Thanks for any hints,
> Paul Lakin
> -- bitwAttb
Well, ruby also gets false for that expression.
As does perl.
Why do you feel that it should return true? Remember that floating
point numbers in computers don't follow the same rules as real
numbers in math.
Notably, since there are a limited number of bits of precision and
numbers are represented by a binary fraction and an exponent, you can
only exactly represent a small subset of the possible real numbers.
--
Ned Konz
http://bike-nomad.com
GPG key ID: BEEA7EFE
More information about the Squeak-dev
mailing list
|