[R] Rounding
R. Michael Weylandt
michael.weylandt at gmail.com
Sat Jan 5 19:48:48 CET 2013
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.
More information about the R-help
mailing list