[squeak-dev] Re: Float plugin

Andreas Raab andreas.raab at gmx.de
Tue Sep 9 16:21:56 UTC 2008


Bert Freudenberg wrote:
> 
> Am 09.09.2008 um 18:13 schrieb Ang Beepeng:
> 
>>
>> I have wrote a named primitive that returns float, as follows,
>>
>> 1 primsIdentityOfFloat":aFloat"
>> 2     "primitive returning a floating point"
>> 3
>> 4    |aFloat|
>> 5    self export: true.
>> 6    self inline: false.
>> 7   
>> 8    self returnTypeC: 'float'.
>> 9    aFloat := interpreterProxy stackFloatValue: 0.
>> 10    self var: aFloat type:' float '.
>> 11    interpreterProxy pop:2.
>> 12    interpreterProxy push: (interpreterProxy floatObjectOf: aFloat).
>>
>> The primitive returns correct answer, but only until fourth or fifth 
>> decimal
>> points. For example, if the answer is "4.88888", primitive returns
>> "4.888880014419556". I added several steps, line 8 , 10 & 12, trying to
>> return or declare the correct data type or object both in C and also in
>> Smalltalk. But I still do not get the correct answer.
>> What can be corrected for higher precision answer? Thanks.
> 
> 
> Squeak Floats are C doubles.

And consequently the above should be typed as:
 >> 10    self var: aFloat type:' double '.
                                 ^^^^^^^^

Also, note that:
* the declaration should precede the assignment (i.e., switch lines 9 
and 10 around)
* the returnTypeC: declaration in line 8 is completely pointless since 
you return the float on the Smalltalk stack not the C stack and the 
return value of the primitive is ignored. Just get rid of line 8.

Cheers,
   - Andreas



More information about the Squeak-dev mailing list