I would like to print e.g. 1000 or 2000 or 15000 decimals of pi value using R?
Now I get only six
> pi
[1] 3.141593
How to achieve this?
I would like to print e.g. 1000 or 2000 or 15000 decimals of pi value using R?
Now I get only six
> pi
[1] 3.141593
How to achieve this?
One of the easiest algorithms to use is probably a spigot. I don't know
R
but it's probably good enough to implement the ideas here.If you don't want to do the calculation yourself then you could look the number up. For example
would produce
R works with the underlying system's floating point data type which typically have around 16 significant decimal figures.
If you want lots of digits of pi then you'll need to hold them in a character array of some such construct. You simply can't fit more than a handful into an R numeric value.
If you wish to generate the digits yourself then a websearch will reveal many articles outlining algorithms to do the job. Or you can find plenty of sites that just list pi to a gazillion digits.
It is very much possible. Please download package Rmpfr.
Then, use following:
It will give value of pi correct to 1000 decimal places.
Not sure whether you can print 1000 or 2000, but this way you can specify how many digits are printed:
Using the R package bc (which is available at the foregoing link, not on CRAN):