How to bake Pi with one cup of Java

So I just watched a video on the calculation of Pi, and was intrigued to write my own little Pi calculator:

In action:

Personally, this clarified my understanding of how Pi is calculated more than just seeing it in that video or in a book.

 

Update:

I punched in the maximum value of iterations (9223372036854775807) and wasn’t really sure how long it would take to compute… I timed 10000 iterations at about 0.6 seconds, so according to my calculations, it will take 1.7 MILLION years to compute pi through that many iterations!

My mind has just been blown through a new perspective of what a massive number 9223372036854775807 really is.

Leave a Reply

Your email address will not be published. Required fields are marked *