[squeak-dev] Float differences

Bert Freudenberg bert at freudenbergs.de
Wed Apr 25 20:28:07 UTC 2012


On 25.04.2012, at 13:20, Sven Van Caekenberghe wrote:

> Hi,
> 
> The following code
> 
> ((-10 to: 10) collect: [ :each | each * Float pi ])
> =
> ((((-10 to: 10) collect: [ :each | each * Float pi ]) 
> 	collect: [ :each | each asString])
> 		collect: [ :each | Float readFrom: each ])
> 
> returns true on Pharo 1.4 and false on Squeak 4.3
> Some of the Floats in the array compare equal, some not.
> 
> Similary, (10 raisedTo: -100) asFloat
> 
> prints as '1.0e-100' in Pharo and as ' 9.99999999999999e-101' in Squeak.
> 
> I know that comparing Floats on equality is often dangerous and that #closeTo: is better.
> But I would like to understand how there could be such a difference between the two.

If you use storeString instead of asString it will be the same. E.g.

	(10 raisedTo: -100) asFloat storeString 
	==> '1.0e-100'

- Bert -




More information about the Squeak-dev mailing list