The particular algorithm used in calculating Pi is one which converges to Pi as you add terms; it’s not calculating out to a number of digits, although I might try that one as well at some point.
Here’s the output from a run; it’s interesting how it gets closer and closer, but… Another interesting thing is how, say, in the run with 10K terms it is off by a digit in the middle and subsequent ones are correct — 3.14149265359 instead of 3.141592653589.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
Calculating 1000 terms Final pi/4 (approx., 1000 terms): 0.7851481634599485 Actual pi/4: 0.7853981633974483 Final pi (approx., 1000 terms): 3.140592653839794 Actual pi: 3.141592653589793 real 0m0.128s user 0m0.109s sys 0m0.017s Calculating 10000 terms Final pi/4 (approx., 10000 terms): 0.7853731633975086 Actual pi/4: 0.7853981633974483 Final pi (approx., 10000 terms): 3.1414926535900345 Actual pi: 3.141592653589793 real 0m0.131s user 0m0.109s sys 0m0.021s Calculating 100000 terms Final pi/4 (approx., 100000 terms): 0.7853956633974299 Actual pi/4: 0.7853981633974483 Final pi (approx., 100000 terms): 3.1415826535897198 Actual pi: 3.141592653589793 real 0m0.148s user 0m0.127s sys 0m0.024s Calculating 1000000 terms Final pi/4 (approx., 1000000 terms): 0.7853979133974436 Actual pi/4: 0.7853981633974483 Final pi (approx., 1000000 terms): 3.1415916535897743 Actual pi: 3.141592653589793 real 0m0.146s user 0m0.134s sys 0m0.024s Calculating 10000000 terms Final pi/4 (approx., 10000000 terms): 0.7853981383974479 Actual pi/4: 0.7853981633974483 Final pi (approx., 10000000 terms): 3.1415925535897915 Actual pi: 3.141592653589793 real 0m0.213s user 0m0.195s sys 0m0.031s Calculating 10000000 terms Final pi/4 (approx., 10000000 terms): 0.7853981383974479 Actual pi/4: 0.7853981633974483 Final pi (approx., 10000000 terms): 3.1415925535897915 Actual pi: 3.141592653589793 real 0m0.191s user 0m0.183s sys 0m0.025s Calculating 100000000 terms Final pi/4 (approx., 100000000 terms): 0.7853981608973315 Actual pi/4: 0.7853981633974483 Final pi (approx., 100000000 terms): 3.141592643589326 Actual pi: 3.141592653589793 real 0m0.552s user 0m0.530s sys 0m0.032s Calculating 1000000000 terms Final pi/4 (approx., 1000000000 terms): 0.7853981631470126 Actual pi/4: 0.7853981633974483 Final pi (approx., 1000000000 terms): 3.1415926525880504 Actual pi: 3.141592653589793 real 0m3.939s user 0m3.921s sys 0m0.028s |