[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

2 - 2.01 ??

Misiek Sz

10/18/2007 12:50:00 PM

Hey,
How come 2 - 2.01 = -0.00999999999999979 and not -0.01
???
Can someone explain this to me please?
--
Posted via http://www.ruby-....

5 Answers

Jano Svitok

10/18/2007 12:56:00 PM

0

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/ruby-t...

Tim Hunter

10/18/2007 12:57:00 PM

0

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#Accurac....
--
Posted via http://www.ruby-....

Gregory Seidman

10/18/2007 12:57:00 PM

0

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#Accurac...

--Greg


Karl von Laudermann

10/18/2007 12:58:00 PM

0

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-....

This question comes up a lot. Google "floating point errors" for some
good links.

elof

10/18/2007 12:59:00 PM

0




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_gol...

Kristian