Re: [R] -1.1 - 0.1 + 1.2 is NOT null! Why?

2012-07-13 Thread ollestrat
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.

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


Re: [R] -1.1 - 0.1 + 1.2 is NOT null! Why?

2012-07-13 Thread ollestrat
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.

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


Re: [R] -1.1 - 0.1 + 1.2 is NOT null! Why?

2012-07-12 Thread Erdal Karaca
I was just trying to say that Ole might know the technical difference
between "NULL" and "ZERO", but it seemed to be rather a linguistic
confusion...
BTW. the subject contains "null", but the body of the mail correctly states
"zero" :-)


2012/7/12 Patrick Connolly 

> 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 
> |>
> |> >
> |> >
> |> > 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@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@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.
>
> --
> ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.
>___Patrick Connolly
>  {~._.~}   Great minds discuss ideas
>  _( Y )_ Average minds discuss events
> (:_~*~_:)  Small minds discuss people
>  (_)-(_)  . Eleanor Roosevelt
>
> ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.
>

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


Re: [R] -1.1 - 0.1 + 1.2 is NOT null! Why?

2012-07-12 Thread Patrick Connolly
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 
|> 
|> >
|> >
|> > 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@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@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.

-- 
~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.   
   ___Patrick Connolly   
 {~._.~}   Great minds discuss ideas
 _( Y )_ Average minds discuss events 
(:_~*~_:)  Small minds discuss people  
 (_)-(_)  . Eleanor Roosevelt
  
~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.

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


Re: [R] -1.1 - 0.1 + 1.2 is NOT null! Why?

2012-07-11 Thread Richard M. Heiberger
This is a fascinating example.  It is an accident that it looks like it
comes out even.

Here are both sets displayed using hex format where we see exactly what
bits are used
in the internal representation of the numbers.

> dphex <- function(x) {sprintf("%+.13a", x)}

> ones <- c(-1.1,
+   -0.1,
+   1.2,
+   -1.1-0.1+1.2)
>
> twos <- c(-1.2,
+   -0.2,
+   1.4,
+   -1.2-0.2+1.4)
>
> cbind(ones, dphex(ones))
 ones
[1,] "-1.1"  "-0x1.1999ap+0"
[2,] "-0.1"  "-0x1.ap-4"
[3,] "1.2"   "+0x1.3p+0"
[4,] "-2.22044604925031e-16" "-0x1.0p-52"
>
> cbind(twos, dphex(twos))
 twos
[1,] "-1.2" "-0x1.3p+0"
[2,] "-0.2" "-0x1.ap-3"
[3,] "1.4"  "+0x1.6p+0"
[4,] "0""+0x0.0p+0"
>



dphex <- function(x) {sprintf("%+.13a", x)}
ones <- c(-1.1,
  -0.1,
  1.2,
  -1.1-0.1+1.2)

twos <- c(-1.2,
  -0.2,
  1.4,
  -1.2-0.2+1.4)

cbind(ones, dphex(ones))

cbind(twos, dphex(twos))



As you can see, both sets of numbers are repeating hexadecimals.  When we
run out
of digits at the end at the 53 bit (13th hex digit after the hex point) the
repeat pattern is
broken.  The '9' is rounded up to 'a'.  It is an accident that the rounding
of the twos values
cancels to give an apparent sum of 0.


On Tue, Jul 10, 2012 at 6:23 PM, massimodisasha wrote:

> 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@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
>
> >
>
> __**
> 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]]

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


Re: [R] -1.1 - 0.1 + 1.2 is NOT null! Why?

2012-07-10 Thread arun
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 
To: ollestrat ; r-help@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:
> 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.
...

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
>

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


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


Re: [R] -1.1 - 0.1 + 1.2 is NOT null! Why?

2012-07-10 Thread Erdal Karaca
german "Null" == english "zero" :-)

2012/7/10 Rolf Turner 

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


Re: [R] -1.1 - 0.1 + 1.2 is NOT null! Why?

2012-07-10 Thread massimodisasha

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

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


Re: [R] -1.1 - 0.1 + 1.2 is NOT null! Why?

2012-07-10 Thread Rolf Turner

But R-ish NULL is *NOT* equal to R-ish zero, and that's
what counts here.

 cheers,

 Rolf Turner

On 11/07/12 09:19, Erdal Karaca wrote:
> german "Null" == english "zero" :-)
>
> 2012/7/10 Rolf Turner  >
>
>
>
> 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
>
>

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


Re: [R] -1.1 - 0.1 + 1.2 is NOT null! Why?

2012-07-10 Thread Rolf Turner



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


Re: [R] -1.1 - 0.1 + 1.2 is NOT null! Why?

2012-07-10 Thread William Dunlap
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-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
> Behalf Of ollestrat
> Sent: Tuesday, July 10, 2012 1:17 PM
> To: r-help@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@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.

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


Re: [R] -1.1 - 0.1 + 1.2 is NOT null! Why?

2012-07-10 Thread Richard M. Heiberger
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  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]]

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


[R] -1.1 - 0.1 + 1.2 is NOT null! Why?

2012-07-10 Thread ollestrat
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.