Skip to content

-1.1 - 0.1 + 1.2 is NOT null! Why?

13 messages · Richard M. Heiberger, William Dunlap, Rolf Turner +5 more

#
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
#
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:
#
Il 7/10/12 4:17 PM, ollestrat ha scritto:
...

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
 >
#
Hi,

Perl:
perl -e 'print -1.1-0.1+1.2. "\n";'
-2.22044604925031e-16
perl -e 'print -1.2-0.2+1.4. "\n";'
0


A.K.




----- Original Message -----
From: massimodisasha <massimodisasha at gmail.com>
To: ollestrat <stratman1 at gmx.de>; r-help at r-project.org
Cc: 
Sent: Tuesday, July 10, 2012 6:23 PM
Subject: Re: [R] -1.1 - 0.1 + 1.2 is NOT null! Why?

Il 7/10/12 4:17 PM, ollestrat ha scritto:
...

Python :
-2.220446049250313e-16
0.0
R :
[1] -2.220446e-16
[1] 0
______________________________________________
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.
1 day later
#
On Tue, 10-Jul-2012 at 11:19PM +0200, Erdal Karaca wrote:
|> german "Null" == english "zero" :-)

German "Gift" == English "poison"  :-(







|> 
|> 2012/7/10 Rolf Turner <rolf.turner at xtra.co.nz>
|> 
|> >
|> >
|> > 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
|> >>
|> >
|> > ______________________________________________
|> > 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.
|> >
|> 
|> 	[[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.
#
Thank you for the explanation. Good to know about the issue how double values
are "constructed" by a bit system. This makes me handling double values with
care in using it in R or aother languages control structures etc. 

Thank you also for the hint concerning the Null vs. Zero vs.. issue. Yes,
the subject title is misleading.. 


--
View this message in context: http://r.789695.n4.nabble.com/1-1-0-1-1-2-is-NOT-null-Why-tp4636053p4636432.html
Sent from the R help mailing list archive at Nabble.com.