[R] number of decimal places in a number?
savicky at cs.cas.cz
Mon Jul 9 22:33:05 CEST 2012
On Mon, Jul 09, 2012 at 07:52:18AM -0500, Jim Plante wrote:
> I don't know how significant this is, but WolframAlpha's value of pi disagrees with R's at about the 16th decimal:
> Probably not of interest to anyone but astronomers, nanotechnologists, and us anal lurkers though. We went to the moon and back on two decimal places.
This does not belong to this thread.
The reason for the difference is explained in ?double
All R platforms are required to work with values conforming to the
IEC 60559 (also known as IEEE 754) standard. This basically works
with a precision of 53 bits, and represents to that precision a
range of absolute values from about 2e-308 to 2e+308.
Pi in binary is
and the brackets separate the first 53 significant bits. So, the double
precision pi, which is represented by these bits, is slightly smaller than
the exact value. The difference is not specific to R, but to the standard
computer arithmetic implemented in the hardware, which uses 53 bits.
Hope this helps.
P.S. If you want to make further comments, please, open a new thread.
More information about the R-help