Forum: Ruby 2 - 2.01 ??

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
9176dbda5485fea69a18d92005a75c62?d=identicon&s=25 Great John (nicpon)
on 2007-10-18 14:49
Hey,
How come 2 - 2.01 = -0.00999999999999979 and not -0.01
???
Can someone explain this to me please?
97550977337c9f0a0e1a9553e55bfaa0?d=identicon&s=25 Jano Svitok (Guest)
on 2007-10-18 14:55
(Received via mailing list)
On 10/18/07, Michal Sza <nicpon@nicpon.net> wrote:
> Hey,
> How come 2 - 2.01 = -0.00999999999999979 and not -0.01
> ???
> Can someone explain this to me please?

http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/...
B33ea5c12d767bfd1253940a960274f5?d=identicon&s=25 Tim Hunter (timhunter)
on 2007-10-18 14:57
Michal Sza wrote:
> Hey,
> How come 2 - 2.01 = -0.00999999999999979 and not -0.01
> ???
> Can someone explain this to me please?

Because 0.01 cannot be represented accurately in binary. See
http://en.wikipedia.org/wiki/Floating_point#Accura....
Bf6862e2a409078e13a3979c00bba1d6?d=identicon&s=25 Gregory Seidman (Guest)
on 2007-10-18 14:58
(Received via mailing list)
On Thu, Oct 18, 2007 at 09:49:37PM +0900, Michal Sza wrote:
> Hey,
> How come 2 - 2.01 = -0.00999999999999979 and not -0.01
> ???
> Can someone explain this to me please?

http://en.wikipedia.org/wiki/Floating_point#Accura...

--Greg
Be9f5eca2661acace327b45f8b1acabf?d=identicon&s=25 unknown (Guest)
on 2007-10-18 15:01
(Received via mailing list)
On Thu, 18 Oct 2007 21:49:37 +0900, Michal Sza <nicpon@nicpon.net>
wrote:
> Hey,
> How come 2 - 2.01 = -0.00999999999999979 and not -0.01
> ???
> Can someone explain this to me please?

Because you are using floating point.

Reas this article for an explanation:

"What Every Computer Scientist Should Know About Floating-Point
Arithmetic"

http://docs.sun.com/source/806-3568/ncg_goldberg.html

  Kristian
9377764fa3b08a1c7bf702d373ee653a?d=identicon&s=25 Karl von Laudermann (Guest)
on 2007-10-18 15:02
(Received via mailing list)
On Oct 18, 8:49 am, Michal Sza <nic...@nicpon.net> wrote:
> Hey,
> How come 2 - 2.01 = -0.00999999999999979 and not -0.01
> ???
> Can someone explain this to me please?
> --
> Posted viahttp://www.ruby-forum.com/.

This question comes up a lot. Google "floating point errors" for some
good links.
This topic is locked and can not be replied to.