[squeak-dev] Float differences

Nicolas Cellier nicolas.cellier.aka.nice at gmail.com
Wed Apr 25 20:38:30 UTC 2012


Yes, Pharo is a bit ahead, I have a change in Squeak/inbox to align
Squeak printing...

Nicolas

Le 25 avril 2012 22:28, Bert Freudenberg <bert at freudenbergs.de> a écrit :
>
> 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