Hello, I fear its a stupid question,..but here it is: If I do this simple calculation with the R console, I surprisingly do not get a zero. Why? -1.1-0.1+1.2 [1] -2.220446e-16 greetings, Ole -- View this message in context: http://r.789695.n4.nabble.com/1-1-0-1-1-2-is-NOT-null-Why-tp4636053.html Sent from the R help mailing list archive at Nabble.com. [[alternative HTML version deleted]]
This is the behavior of the floating point number representation. Decimal fractions do not come out even in binary notation. Please see FAQ 7.31 On Tue, Jul 10, 2012 at 4:17 PM, ollestrat <stratman1@gmx.de> wrote:> Hello, > > I fear its a stupid question,..but here it is: > > If I do this simple calculation with the R console, I surprisingly do not > get a zero. Why? > > -1.1-0.1+1.2 > [1] -2.220446e-16 > > > greetings, Ole > > -- > View this message in context: > http://r.789695.n4.nabble.com/1-1-0-1-1-2-is-NOT-null-Why-tp4636053.html > Sent from the R help mailing list archive at Nabble.com. > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >[[alternative HTML version deleted]]
It is for the same reason that if you must work with numbers stored with 2 significant decimal digits 1-(1/3+1/3+1/3) is 0.01 (== 10 ^ -2). Double precision numbers, supported by your computer hardware and used by R, are stored using 52 significant binary digits and 2^-52 is about -2.220446e-16. (By the way, in R zero and NULL are different things: the former is numeric and the latter is not.) Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On > Behalf Of ollestrat > Sent: Tuesday, July 10, 2012 1:17 PM > To: r-help at r-project.org > Subject: [R] -1.1 - 0.1 + 1.2 is NOT null! Why? > > Hello, > > I fear its a stupid question,..but here it is: > > If I do this simple calculation with the R console, I surprisingly do not > get a zero. Why? > > -1.1-0.1+1.2 > [1] -2.220446e-16 > > > greetings, Ole > > -- > View this message in context: http://r.789695.n4.nabble.com/1-1-0-1-1-2-is-NOT- > null-Why-tp4636053.html > Sent from the R help mailing list archive at Nabble.com. > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.
In addition to taking cognisance of Richard Heiberger's reply you should also learn to distinguish between the concept of "null" and "zero". They are not at all the same thing. cheers, Rolf Turner On 11/07/12 08:17, ollestrat wrote:> Hello, > > I fear its a stupid question,..but here it is: > > If I do this simple calculation with the R console, I surprisingly do not > get a zero. Why? > > -1.1-0.1+1.2 > [1] -2.220446e-16 > > > greetings, Ole
Il 7/10/12 4:17 PM, ollestrat ha scritto:> Hello, > > I fear its a stupid question,..but here it is: > > If I do this simple calculation with the R console, I surprisingly do not > get a zero. Why? > > -1.1-0.1+1.2 > [1] -2.220446e-16 > > > greetings, Ole > > -- > View this message in context: http://r.789695.n4.nabble.com/1-1-0-1-1-2-is-NOT-null-Why-tp4636053.html > Sent from the R help mailing list archive at Nabble.com. > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.... Python : >>> -1.1-0.1+1.2 -2.220446049250313e-16 >>> -1.2-0.2+1.4 0.0 >>> R : > -1.1-0.1+1.2 [1] -2.220446e-16 > -1.2-0.2+1.4 [1] 0 >
Someone pointed me to this paper: http://www.validlab.com/goldberg/paper.pdf -- View this message in context: http://r.789695.n4.nabble.com/1-1-0-1-1-2-is-NOT-null-Why-tp4636053p4636433.html Sent from the R help mailing list archive at Nabble.com.