Floating point

Andreas Raab andreas.raab at gmx.de
Tue Dec 17 01:38:26 UTC 2002


Paul,

> Executing this in a workspace on my machine returns 'false' 
> incorrectly  

Executing this on your *machine* will return false. Floats are limited
precision representation of "real numbers" and you are simply seeing one
of the effects. That's why Squeak has true fractions which will compute
the result correctly (though slowly!) e.g.,

x := 11/10.
( ( (x + x + x) / 3) = ( ( x + x + x + x + x + x  ) / 6 ) )
=> true

x := 1.1.
( ( (x + x + x) / 3) = ( ( x + x + x + x + x + x  ) / 6 ) )
=> false

Cheers,
  - Andreas

> -----Original Message-----
> From: squeak-dev-admin at lists.squeakfoundation.org 
> [mailto:squeak-dev-admin at lists.squeakfoundation.org] On 
> Behalf Of bitwAttb
> Sent: Monday, December 16, 2002 4:48 PM
> To: squeak-dev at lists.squeakfoundation.org
> Subject: Floating point 
> 
> 
> 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
> 




More information about the Squeak-dev mailing list