[R] Rounding error in seq(...)

Nordlund, Dan (DSHS/RDA) NordlDJ at dshs.wa.gov
Thu Oct 1 00:25:24 CEST 2009


> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On
> Behalf Of Douglas Bates
> Sent: Wednesday, September 30, 2009 3:06 PM
> To: Peter Dalgaard
> Cc: r help; Duncan Murdoch
> Subject: Re: [R] Rounding error in seq(...)
> 
> On Wed, Sep 30, 2009 at 2:32 PM, Peter Dalgaard<p.dalgaard at biostat.ku.dk>
> wrote:
> > Martin Batholdy wrote:
> >>
> >> hum,
> >>
> >> can you explain that a little more detailed?
> >> Perhaps I miss the background knowledge - but it seems just absurd to me.
> >>
> >> 0.1+0.1+0.1 is 0.3 - there is no rounding involved, is there?
> >>
> >> why is
> >> x <- 0.1 + 0.1 +0.1
> >> not equal to
> >> y <- 0.3
> >
> > Remember that this is in BINARY arithmetic. It's really not any stranger
> > than the fact that 1/3 + 1/3 != 2/3 in finite accuracy decimal arithmetic
> > (0.33333 + 0.33333 = 0.66666 != 0.66667).
> 
> In an earlier thread on this theme I believe that someone quoted Brian
> Kernighan as saying "10 times 0.1 is hardly ever 1" but I haven't been
> able to track down the quote.  Can anyone point us to such a quote?
> It summarizes the situation succinctly,
> 

The first page of this document references: http://www.stats.ox.ac.uk/~ruth/RCourse/Numerics.pdf

 ‘The Elements of Programming Style’ by Kernighan and Plauger

Hope this is helpful,

Dan

Daniel J. Nordlund
Washington State Department of Social and Health Services
Planning, Performance, and Accountability
Research and Data Analysis Division
Olympia, WA  98504-5204




More information about the R-help mailing list