michael.b.masi
3/31/2005 3:57:00 PM
Glenn Parker wrote:
> horati0@linuxmail.org wrote:
> > not really an oddity, more a lack of understanding on my part
regarding
> > ruby's internal type conversion...
> >
> > (100*(1.15-1))
> > => 15.0
> >
> > (100*(1.15-1)).to_int
> > => 14
> >
> > (100*(1.15-1)).to_int.round
> > => 15
>
> FWIW, I get 14. Perhaps you meant (100*(1.15-1)).round.to_int ?
>
oops, yep thats what i meant. thanks for all the replies to my query;
i figured it had something to do with the internal representation of fp
numbers.
this whole thing started as a conversation i was having with my dad
about the relative merits of various programming languages. he is a
die-hard xbasic user, and pointed me to the following post on an xb
list:
---------------------------------------------------------------------
[snip]
Message: 7
Date: Wed, 30 Mar 2005 12:59:42 -0000
From: "Bruno Schaefer" <bup.schaefer@...>
Subject: XBasic is one of the best!
I'm back now to work with XBasic, because there are strange things
with other languages.
If you try to calculate the following simple expression
INT(100*(1.15-1))
XBasic produces the correct result: 15.
This is a calculation, which is solved by children easy.
But try this with other languages
(e.g. newLISP, Visual Basic, Liberty Basic, IBasic, Yabasic, Python)
you will get the result
14 !!!!?
What a nonsense ! Does somebody understand this ?
This is one the reason for me to use XBasic!
---------------------------------------------------------------------
i'm assuming that since this behaviour is exhibited in ruby and the
rest of the above "other languages" and NOT xbasic that it is really
due to an idiosyncracy of xbasic that the "right" answer comes out.
so the question becomes, what is different about xbasic's internal
numeric representation that allows it to give a correct answer to this
seemingly simple number manipulation?
horati0