Actually funny you ask because I can’t seem to make the float class provide
rounding errors. I have been searching on the web but can’t seem to make Ruby
give me rounding errors. I was under the impressions that floats where always
inaccurate, is this not the case in Ruby? The reason I ask is because I am
working on a general Money class. Currently I am backing this with a Fixnum
in cents, but would prefer to have some sort of decimal type that doesn’t put
a limit on 2 cent places. Very interesting indeed…
irb(main):001:0> x = 1.5e10
1.5e+10
irb(main):002:0> x - 1 == x
false
irb(main):003:0> x = 1.5e20
1.5e+20
irb(main):004:0> x - 1 == x
true
Now obviously you’re not going to be dealing with amounts of money that
large, but it shows the inherent inaccuracy in floats.
Tim Bates
···
On Tue, Jun 24, 2003 at 05:54:42PM +0900, Holden Glova wrote:
Actually funny you ask because I can’t seem to make the float class provide
rounding errors. I have been searching on the web but can’t seem to make Ruby
give me rounding errors. I was under the impressions that floats where always
inaccurate, is this not the case in Ruby?
Interesting. I have also noted this and figured out that maybe Matz has
been clever enough to design the input/output routines of float numbers
such that the process is reversible (I mean from float to string and back).
However, I did not trust this and besides it is the issue of reversibility
from string to float and back (more than, say, 17 digits in the original
string).
Tore Haug-Warberg
···
At 18:41 24.06.03 +0900, Tim Bates wrote:
On Tue, Jun 24, 2003 at 05:54:42PM +0900, Holden Glova wrote:
Actually funny you ask because I can’t seem to make the float class
provide
rounding errors. I have been searching on the web but can’t seem to
make Ruby
give me rounding errors. I was under the impressions that floats where
always
inaccurate, is this not the case in Ruby?
“Tore Haug-Warberg” haugwarb@chembio.ntnu.no schrieb im Newsbeitrag
news:4.3.2.7.0.20030624115646.00be2100@pop.chembio.ntnu.no…
Actually funny you ask because I can’t seem to make the float class
provide
rounding errors. I have been searching on the web but can’t seem to
make Ruby
give me rounding errors. I was under the impressions that floats
where
always
inaccurate, is this not the case in Ruby?
Interesting. I have also noted this and figured out that maybe Matz has
been clever enough to design the input/output routines of float numbers
such that the process is reversible (I mean from float to string and
back).
However, I did not trust this and besides it is the issue of
reversibility
from string to float and back (more than, say, 17 digits in the original
string).