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.
Ang Beepeng
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.
- Bert -
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
"Ang" == Ang Beepeng beepeng86@yahoo.com writes:
Ang> The primitive returns correct answer, but only until fourth or fifth decimal Ang> points. For example, if the answer is "4.88888", primitive returns Ang> "4.888880014419556". I added several steps, line 8 , 10 & 12, trying to Ang> return or declare the correct data type or object both in C and also in Ang> Smalltalk. But I still do not get the correct answer.
Ignoring the "float" vs "double" issue, you *do* realize that 4.88888 has no precise IEEE floating point representation, and thus will never be *precisely* that value, right?
Even 0.1 has no precise representation... it has to be truncated to fit within the 53(?) bits of precision. So 0.1 added 10 times might not be precisely 1.0. Most "flost to string" converters stop when they start getting into the "imaginary noise" bits, and if you ask for a longer value, you'll get garbage.
Thanks for all the helps.
Say, if I'm going to create a plugin into a newly downloaded source release directory,
eg, C:\SqueakVM\platforms\win32\build ,
I need to generate the plugins in "VMMaker - Plugins" first, before I generate the plugin that I write. Is it true? Is it because plugins in "VMMaker - Plugins" help creation of a new plugin?
Thanks. Ang Beepeng
Ang Beepeng wrote:
Say, if I'm going to create a plugin into a newly downloaded source release directory,
eg, C:\SqueakVM\platforms\win32\build ,
I need to generate the plugins in "VMMaker - Plugins" first, before I generate the plugin that I write. Is it true? Is it because plugins in "VMMaker - Plugins" help creation of a new plugin?
No you don't have to. "VMMaker - Plugins" serve as a Collection of all the plugins you did. It is just to make it look neater as all the plugins are grouped together. Well, you can just edit the category of your plugin as "VMMaker - Plugins" to have your class listed in the same group.
Just make sure you subclassed it under the InterpreterPlugin.
squeak-dev@lists.squeakfoundation.org