Re: [R] calculate differences - strange outcome

2008-07-20 Thread Bernardo Rangel Tura
Em Qui, 2008-07-17 às 11:47 +0200, Kunzler, Andreas escreveu:
 Dear List,
 
 I ran into some trouble by calculating differences. For me it is
 important that differences are either 0 or not.
 
 So I don't understand the outcome of this calculation
 
 865.56-(782.86+0+63.85+18.85+0)
 [1] -1.136868e-13
 
 I run R version 2.71 on WinXP

Hi Andreas Kunzler,

Your problem is cause by numeric represntation in computer
(Floating-Point numbers) and this topic is explain in R FAQ 7.31

But the solution for your calculations is possible using the guard
digits approach, so  if you needd solve:

865.56-(782.86+0+63.85+18.85+0)

Using 

865.56/100 -(782.86+0+63.85+18.85+0)/100

More details in http://docs.sun.com/source/806-3568/ncg_goldberg.html
(This links is indicated in R FAQ 7.31)


-- 
Bernardo Rangel Tura, M.D,MPH,Ph.D
National Institute of Cardiology
Brazil

__
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] calculate differences - strange outcome

2008-07-17 Thread Kunzler, Andreas
Dear List,

I ran into some trouble by calculating differences. For me it is
important that differences are either 0 or not.

So I don't understand the outcome of this calculation

865.56-(782.86+0+63.85+18.85+0)
[1] -1.136868e-13

I run R version 2.71 on WinXP

I could solve my problem by using
round()
but I would like to know the reason.
Maybe someone can help me?

Thanx

__
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] calculate differences - strange outcome

2008-07-17 Thread Berwin A Turlach
On Thu, 17 Jul 2008 11:47:42 +0200
Kunzler, Andreas [EMAIL PROTECTED] wrote:

 I ran into some trouble by calculating differences. For me it is
 important that differences are either 0 or not.

If that is the case, restrict yourself to calculating with integers. :)

 So I don't understand the outcome of this calculation
 
 865.56-(782.86+0+63.85+18.85+0)
 [1] -1.136868e-13
 
 I run R version 2.71 on WinXP
 
 I could solve my problem by using
 round()
 but I would like to know the reason.
 Maybe someone can help me?

FAQ 7.31 and the reference cited therein should shed light on your
problem.

Best wishes,

Berwin

=== Full address =
Berwin A TurlachTel.: +65 6516 4416 (secr)
Dept of Statistics and Applied Probability+65 6516 6650 (self)
Faculty of Science  FAX : +65 6872 3919   
National University of Singapore 
6 Science Drive 2, Blk S16, Level 7  e-mail: [EMAIL PROTECTED]
Singapore 117546http://www.stat.nus.edu.sg/~statba

__
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] calculate differences - strange outcome

2008-07-17 Thread Mark Difford

Hi Andreas,

It's because you are dealing with binary or floating point calculations, not
just a few apples and oranges, or an abacus (which, by the way, is an
excellent calculating device, and still widely used in some [sophisticated]
parts of the world).

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

HTH, Marks.


Kunzler, Andreas wrote:
 
 Dear List,
 
 I ran into some trouble by calculating differences. For me it is
 important that differences are either 0 or not.
 
 So I don't understand the outcome of this calculation
 
 865.56-(782.86+0+63.85+18.85+0)
 [1] -1.136868e-13
 
 I run R version 2.71 on WinXP
 
 I could solve my problem by using
 round()
 but I would like to know the reason.
 Maybe someone can help me?
 
 Thanx
 
 __
 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.
 
 

-- 
View this message in context: 
http://www.nabble.com/calculate-differences---strange-outcome-tp18505010p18505498.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] calculate differences - strange outcome

2008-07-17 Thread Duncan Murdoch

Kunzler, Andreas wrote:

Dear List,

I ran into some trouble by calculating differences. For me it is
important that differences are either 0 or not.

So I don't understand the outcome of this calculation

865.56-(782.86+0+63.85+18.85+0)
[1] -1.136868e-13

I run R version 2.71 on WinXP

I could solve my problem by using
round()
but I would like to know the reason.
Maybe someone can help me?


This is FAQ 7.31.

Duncan Murdoch

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