[Newbies] Re: asInteger bug?

nicolas cellier nicolas.cellier.aka.nice at gmail.com
Mon Jun 27 18:56:51 UTC 2011


bb <bblochl <at> arcor.de> writes:

> 
> There I found a problem with asInteger:
> 
> According to the x3j20 ansi standard Float>>asInteger and
> Double>>asInteger should be equivalent to sending rounded. You can
> download the final draft revision for free:
> wiki.squeak.org/squeak/uploads/172/standard_v1_9-indexed.pdf.
> 
> I tried that in squeak 4.2:
> 1.11 asInteger 1
> 1.99 asInteger 1
> 1.11 rounded 1
> 1.99 rounded 2
> 
> Astonishing is the result as well:
> (0.6 / 0.2) asInteger 2
> 

Did you try this code:

{(0.6/0.2)=3. (0.6/0.2)<3. }.

My guessed answer is #(false true)

> That seems to be the conversion Problem of odd decimals to binary, well
> known from most of the programming languages.
> 
> Here another experiment:
> 2.999999999999 asInteger   2
> 2.999999999999 rounded 3
> 2.999999999999999 asInteger  2
> 2.9999999999999999 asInteger 3
> 

Did you try this:

2.9999999999999999 = 3.0

I didn't neither, but my guess is that is will answer true.

> Is squeak/Smalltalk not x3j20 ansi standard compliable?
> 
> Regards
> 
> B. Blochl
> 

Obviously, regarding this behavior, Squeak does not happen to be compliant.

Due to inexact behaviour of Float, it seems wiser to me to round rather than
truncate, as recommended by the standard (and as illustrated by your very good
0.6/0.2 example).

I don't know what would be the consequences of such a change though...

Nicolas



More information about the Beginners mailing list