[R] number of decimal places in a number?
Petr Savicky
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:
>
> Wpi->3.141592653589793238462643383279502884197169399375105
> ......................^
> Rpi->3.14159265358979311599796346854418516
>
> 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.
Hi.
This does not belong to this thread.
The reason for the difference is explained in ?double
Double-precision values:
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
(11.001001000011111101101010100010001000010110100011000)01000110100110001001100011001...
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.
Petr Savicky.
P.S. If you want to make further comments, please, open a new thread.
More information about the R-help
mailing list