To celebrate pi day with my school I created a function to compute an approximation for pi. It seems R has a maximum digit preference of 16 digits by default. Here is my code:

piestimate<-function(r,s){

inscribed.p<-s*sin(2*pi/s)/sin((pi-(2*pi)/s)/2)/2

circumscribed.p<-s*sin(pi/s)/sin(pi/2-(pi/s))

(inscribed.p+circumscribed.p)/2->estimate

return(format(estimate,digits=20))}

I used the format command to control how many digits were produced by the approximation, but the maximum output seems to be 16. I used the following command to run the program and find the first 16 correct digits of pi.

piestimate(1,99999999)

This computation took miliseconds to compute in R. It took mathematicians without computer capabilities years to compute this approximation accurately. I wonder if there is some way to make R compute this more precisely?

### Like this:

Like Loading...

*Related*