Re: [R] calculate differences - strange outcome

From: Bernardo Rangel Tura <tura_at_centroin.com.br>
Date: Sun, 20 Jul 2008 09:02:45 -0300

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_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.
Received on Sun 20 Jul 2008 - 12:05:40 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sun 20 Jul 2008 - 12:31:59 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive