Y
Yossef Mendelssohn
I recall seeing a few posts about the "fun" involving floating-point
representation of numbers, but this is something I found a little
surprising:
Cassady:~ yossef$ irb --prompt simple=> 0
Odd, isn't it? What's going on here?
=> 19.76
Ah, maybe this is it.
=> 0
Nope!
Well, a bit of experimentation led me to this, which demonstrates two
threshold points.
=> 0
It appears 19.75999999999999 (that's 12 9s, or 14 decimal places
total) is just close enough to *display* rounded up, but not actually
*become* that number. Adding two more 9s makes it close enough to
actually become that number.
No question or call for help, really. I just wanted to point out
something that intrigued me.
representation of numbers, but this is something I found a little
surprising:
Cassady:~ yossef$ irb --prompt simple=> 0
Odd, isn't it? What's going on here?
=> 19.76
Ah, maybe this is it.
=> 0
Nope!
Well, a bit of experimentation led me to this, which demonstrates two
threshold points.
=> 0
It appears 19.75999999999999 (that's 12 9s, or 14 decimal places
total) is just close enough to *display* rounded up, but not actually
*become* that number. Adding two more 9s makes it close enough to
actually become that number.
No question or call for help, really. I just wanted to point out
something that intrigued me.