title: Using basic arithmetics for calculating Pi with arbitary precision
body: <p>I am looking for a formula/algorithm to calculate PI~3.14 in a given precision.</p>
  
  <p>The formula/algorithm must have only very basic arithmetic as</p>
  
  <ul>
  <li>+: Addition</li>
  <li>-: Subtraction</li>
  <li>*: Multiplication</li>
  <li>/: Divison</li>
  </ul>
  
  <p>because I want to implement these operations in C++ and want to keep the implementation as simple as possible (no bignum library is allowed).</p>
  
  <p>I have found that this formula for calculating Pi is pretty simple:</p>
  
  <pre><code>Pi/4 = 1 - 1/3 + 1/5 - 1/7 + ...  = sum( (-1)^(k+1)/(2*k-1) , k=1..inf )
  </code></pre>
  
  <p>(note that (-1)^(k+1) can be implemented easily by above operators).</p>
  
  <p>But the problem about this formula is the inability to specify the number of digits to calculate. In other words, there is no direct way to determine when to stop the calculation.</p>
  
  <p>Maybe a workaround to this problem is calculating the difference between <code>n-1</code>th and <code>n</code>th calculated term and considering it as the current error.</p>
  
  <p>Anyway, I am looking for a formula/algorithm that have these properties and also converges faster to Pi</p>