08-24-2022, 12:28 AM
(08-22-2022, 10:56 PM)SMcNeill Wrote: Here's my little attempt at finding Pi. This relies on some very impressive math formulas and such, but it can calculate up to a million digits of PI for us in about 1/10th of a second! (Just expect QB64 to spend quite a bit longer to print the results to screen for you than that -- our print routine isn't very quick at all!)
The program here is a little too large to fit and play nicely inside a code box, so I'll attached it below for ease of download and reference.
I hope you appreciate all the time and effort I put into this for you @Pete! I doubt you'll ever find another method any more accurate or faster than this one!!
Yeah, that code deserves a pi in the face! Lemon comes to mind.
After doing some reading, I found Ramanujan's method to be interesting, but to program it I'd have to go back in time, 50 years, and re-learn how to do factorials in linear equations. Of course, calculating it to just 6 decimal places is a snap, as at n=zero, all the factorials drop out! (exclamation point after out is a pun at factorials.) Iterations past that require two factorial computations per iteration.
Other interesting things I came across online was the other guys pi formula I experimented with in my string math routine works, but get this, it apparently takes 5 million iterations to do what Ramanujan's method does in just one; and apparently pi to six places is good enough to measure the globe within 1-meter of accuracy. Bad news, @SMcNeill . That 3-feet is coming out of your farm!!! Consider it cropped.
Pete