Hi, Can someone explain this:> options(digits=20) > 1/3[1] 0.33333333333333331483 Why the 1483 at the end? Thanks, David. david-arnolds-macbook-pro-2:~ darnold$ R --version R version 2.15.2 (2012-10-26) -- "Trick or Treat" Copyright (C) 2012 The R Foundation for Statistical Computing ISBN 3-900051-07-0 Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit) -- View this message in context: http://r.789695.n4.nabble.com/Rounding-tp4654738.html Sent from the R help mailing list archive at Nabble.com.
On Sat, 5 Jan 2013, David Arnold wrote:> Hi, > > Can someone explain this: > >> options(digits=20) >> 1/3 > [1] 0.33333333333333331483 > > Why the 1483 at the end?Due to floating-point arithmetic, see FAQ 7.31.> Thanks, > > David. > > david-arnolds-macbook-pro-2:~ darnold$ R --version > R version 2.15.2 (2012-10-26) -- "Trick or Treat" > Copyright (C) 2012 The R Foundation for Statistical Computing > ISBN 3-900051-07-0 > Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit) > > > > > -- > View this message in context: http://r.789695.n4.nabble.com/Rounding-tp4654738.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > 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. >
On Sat, Jan 5, 2013 at 6:42 PM, David Arnold <dwarnold45 at suddenlink.net> wrote:> Hi, > > Can someone explain this: > >> options(digits=20) >> 1/3 > [1] 0.33333333333333331483 > > Why the 1483 at the end?To be curt, "it's complicated," but it basically comes down to the fact that 1/3 is not expressible by a finite sequence of powers of 2 so it can't be perfectly represented in binary. This is (one of many examples of) a nastyness due to floating-point representation. See R FAQ 7.31 and the documents linked therein for a comprehensive tutorial, but "floating point error" should be enough to guide your googling. Cheers, M> > Thanks, > > David. > > david-arnolds-macbook-pro-2:~ darnold$ R --version > R version 2.15.2 (2012-10-26) -- "Trick or Treat" > Copyright (C) 2012 The R Foundation for Statistical Computing > ISBN 3-900051-07-0 > Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit) > > > > > -- > View this message in context: http://r.789695.n4.nabble.com/Rounding-tp4654738.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > 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.
On 01/06/2013 07:42 AM, David Arnold wrote:> Hi, > > Can someone explain this: > >> options(digits=20) >> 1/3 > [1] 0.33333333333333331483 > > Why the 1483 at the end?There are 10 sorts of people; those who understand binary arithmetic and those who don't. See also FAQ 7.31. cheers, Rolf Turner [[alternative HTML version deleted]]