<p>I'm looking for the fastest way to obtain the value of π, as a personal challenge. More specifically, I'm using ways that don't involve using <code>#define</code> constants like <code>M_PI</code>, or hard-coding the number in.</p>

<p>The program below tests the various ways I know of. The inline assembly version is, in theory, the fastest option, though clearly not portable. I've included it as a baseline to compare against the other versions. In my tests, with built-ins, the <code>4 * atan(1)</code> version is fastest on GCC 4.2, because it auto-folds the <code>atan(1)</code> into a constant. With <code>-fno-builtin</code> specified, the <code>atan2(0, -1)</code> version is fastest.</p>

<p>Here's the main testing program (<code>pitimes.c</code>):</p>

<pre class="lang-c prettyprint-override"><code>#include &lt;math.h&gt;
#include &lt;stdio.h&gt;
#include &lt;time.h&gt;

#define ITERS 10000000
#define TESTWITH(x) {                                                       \
    diff = 0.0;                                                             \
    time1 = clock();                                                        \
    for (i = 0; i &lt; ITERS; ++i)                                             \
        diff += (x) - M_PI;                                                 \
    time2 = clock();                                                        \
    printf("%s\t=&gt; %e, time =&gt; %f\n", #x, diff, diffclock(time2, time1));   \
}

static inline double
diffclock(clock_t time1, clock_t time0)
{
    return (double) (time1 - time0) / CLOCKS_PER_SEC;
}

int
main()
{
    int i;
    clock_t time1, time2;
    double diff;

    /* Warmup. The atan2 case catches GCC's atan folding (which would
     * optimise the ``4 * atan(1) - M_PI'' to a no-op), if -fno-builtin
     * is not used. */
    TESTWITH(4 * atan(1))
    TESTWITH(4 * atan2(1, 1))

#if defined(__GNUC__) &amp;&amp; (defined(__i386__) || defined(__amd64__))
    extern double fldpi();
    TESTWITH(fldpi())
#endif

    /* Actual tests start here. */
    TESTWITH(atan2(0, -1))
    TESTWITH(acos(-1))
    TESTWITH(2 * asin(1))
    TESTWITH(4 * atan2(1, 1))
    TESTWITH(4 * atan(1))

    return 0;
}
</code></pre>

<p>And the inline assembly stuff (<code>fldpi.c</code>) that will only work for x86 and x64 systems:</p>

<pre class="lang-c prettyprint-override"><code>double
fldpi()
{
    double pi;
    asm("fldpi" : "=t" (pi));
    return pi;
}
</code></pre>

<p>And a build script that builds all the configurations I'm testing (<code>build.sh</code>):</p>

<pre><code>#!/bin/sh
gcc -O3 -Wall -c           -m32 -o fldpi-32.o fldpi.c
gcc -O3 -Wall -c           -m64 -o fldpi-64.o fldpi.c

gcc -O3 -Wall -ffast-math  -m32 -o pitimes1-32 pitimes.c fldpi-32.o
gcc -O3 -Wall              -m32 -o pitimes2-32 pitimes.c fldpi-32.o -lm
gcc -O3 -Wall -fno-builtin -m32 -o pitimes3-32 pitimes.c fldpi-32.o -lm
gcc -O3 -Wall -ffast-math  -m64 -o pitimes1-64 pitimes.c fldpi-64.o -lm
gcc -O3 -Wall              -m64 -o pitimes2-64 pitimes.c fldpi-64.o -lm
gcc -O3 -Wall -fno-builtin -m64 -o pitimes3-64 pitimes.c fldpi-64.o -lm
</code></pre>

<p>Apart from testing between various compiler flags (I've compared 32-bit against 64-bit too because the optimizations are different), I've also tried switching the order of the tests around. But still, the <code>atan2(0, -1)</code> version still comes out on top every time.</p>

[{'answer_id': 71, 'author': 'Leon Bambrick', 'author_id': 49, 'author_profile': 'https://Stackoverflow.com/users/49', 'pm_score': 6, 'selected': False, 'text': '<p>Here\'s a general description of a technique for calculating pi that I learnt in high school.</p>\n\n<p>I only share this because I think it is simple enough that anyone can remember it, indefinitely, plus it teaches you the concept of "Monte-Carlo" methods -- which are statistical methods of arriving at answers that don\'t immediately appear to be deducible through random processes.</p>\n\n<p>Draw a square, and inscribe a quadrant (one quarter of a semi-circle) inside that square (a quadrant with radius equal to the side of the square, so it fills as much of the square as possible)</p>\n\n<p>Now throw a dart at the square, and record where it lands -- that is, choose a random point anywhere inside the square. Of course, it landed inside the square, but is it inside the semi-circle? Record this fact.</p>\n\n<p>Repeat this process many times -- and you will find there is a ratio of the number of points inside the semi-circle versus the total number thrown, call this ratio x.</p>\n\n<p>Since the area of the square is r times r, you can deduce that the area of the semi circle is x times r times r (that is, x times r squared). Hence x times 4 will give you pi. </p>\n\n<p>This is not a quick method to use. But it\'s a nice example of a Monte Carlo method. And if you look around, you may find that many problems otherwise outside your computational skills can be solved by such methods.</p>\n'}, {'answer_id': 531, 'author': 'nlucaroni', 'author_id': 157, 'author_profile': 'https://Stackoverflow.com/users/157', 'pm_score': 9, 'selected': True, 'text': '<p>The <a href="http://en.wikipedia.org/wiki/Monte_Carlo_method" rel="noreferrer">Monte Carlo method</a>, as mentioned, applies some great concepts but it is, clearly, not the fastest, not by a long shot, not by any reasonable measure. Also, it all depends on what kind of accuracy you are looking for. The fastest π I know of is the one with the digits hard coded. Looking at <a href="http://functions.wolfram.com/Constants/Pi/" rel="noreferrer" title="pi">Pi</a> and <a href="http://functions.wolfram.com/PDF/Pi.pdf" rel="noreferrer" title="pi formulas">Pi[PDF]</a>, there are a lot of formulae.</p>\n\n<p>Here is a method that converges quickly — about 14 digits per iteration. <a href="http://numbers.computation.free.fr/Constants/PiProgram/pifast.html" rel="noreferrer" title="PiFast">PiFast</a>, the current fastest application, uses this formula with the FFT. I\'ll just write the formula, since the code is straightforward. This formula was almost found by <a href="http://numbers.computation.free.fr/Constants/Pi/piramanujan.html" rel="noreferrer">Ramanujan and discovered by Chudnovsky</a>. It is actually how he calculated several billion digits of the number — so it isn\'t a method to disregard. The formula will overflow quickly and, since we are dividing factorials, it would be advantageous then to delay such calculations to remove terms.</p>\n\n<p><img src="https://i.stack.imgur.com/aQMkk.gif" alt="enter image description here"></p>\n\n<p><img src="https://i.stack.imgur.com/2y2l9.gif" alt="enter image description here"></p>\n\n<p>where,</p>\n\n<p><img src="https://i.stack.imgur.com/QqVnB.gif" alt="enter image description here"></p>\n\n<p>Below is the <a href="http://mathworld.wolfram.com/Brent-SalaminFormula.html" rel="noreferrer" title="Brent Salamin Formula">Brent–Salamin algorithm</a>. Wikipedia mentions that when <strong>a</strong> and <strong>b</strong> are "close enough" then <strong>(a + b)² / 4t</strong> will be an approximation of π. I\'m not sure what "close enough" means, but from my tests, one iteration got 2 digits, two got 7, and three had 15, of course this is with doubles, so it might have an error based on its representation and the <em>true</em> calculation could be more accurate.</p>\n\n<pre><code>let pi_2 iters =\n    let rec loop_ a b t p i =\n        if i = 0 then a,b,t,p\n        else\n            let a_n = (a +. b) /. 2.0 \n            and b_n = sqrt (a*.b)\n            and p_n = 2.0 *. p in\n            let t_n = t -. (p *. (a -. a_n) *. (a -. a_n)) in\n            loop_ a_n b_n t_n p_n (i - 1)\n    in \n    let a,b,t,p = loop_ (1.0) (1.0 /. (sqrt 2.0)) (1.0/.4.0) (1.0) iters in\n    (a +. b) *. (a +. b) /. (4.0 *. t)\n</code></pre>\n\n<p>Lastly, how about some pi golf (800 digits)? 160 characters!</p>\n\n<pre><code>int a=10000,b,c=2800,d,e,f[2801],g;main(){for(;b-c;)f[b++]=a/5;for(;d=0,g=c*2;c-=14,printf("%.4d",e+d/a),e=d%a)for(b=c;d+=f[b]*a,f[b]=d%--g,d/=g--,--b;d*=b);}\n</code></pre>\n'}, {'answer_id': 4089, 'author': 'Michiel de Mare', 'author_id': 136, 'author_profile': 'https://Stackoverflow.com/users/136', 'pm_score': 4, 'selected': False, 'text': '<p>If by fastest you mean fastest to type in the code, here\'s the <a href="http://www.golfscript.com/golfscript/examples.html" rel="noreferrer">golfscript</a> solution:</p>\n\n<pre><code>;\'\'6666,-2%{2+.2/@*\\/10.3??2*+}*`1000&lt;~\\;\n</code></pre>\n'}, {'answer_id': 25197, 'author': 'OysterD', 'author_id': 2638, 'author_profile': 'https://Stackoverflow.com/users/2638', 'pm_score': 5, 'selected': False, 'text': '<p>There\'s actually a whole book dedicated (amongst other things) to <em>fast</em> methods for the computation of \\pi: \'Pi and the AGM\', by Jonathan and Peter Borwein (<a href="https://rads.stackoverflow.com/amzn/click/com/047131515X" rel="noreferrer" rel="nofollow noreferrer" title="available on Amazon">available on Amazon</a>).</p>\n\n<p>I studied the AGM and related algorithms quite a bit: it\'s quite interesting (though sometimes non-trivial).</p>\n\n<p>Note that to implement most modern algorithms to compute \\pi, you will need a multiprecision arithmetic library (<a href="http://gmplib.org/" rel="noreferrer">GMP</a> is quite a good choice, though it\'s been a while since I last used it).</p>\n\n<p>The time-complexity of the best algorithms is in O(M(n)log(n)), where M(n) is the time-complexity for the multiplication of two n-bit integers (M(n)=O(n log(n) log(log(n))) using FFT-based algorithms, which are usually needed when computing digits of \\pi, and such an algorithm is implemented in GMP).</p>\n\n<p>Note that even though the mathematics behind the algorithms might not be trivial, the algorithms themselves are usually a few lines of pseudo-code, and their implementation is usually very straightforward (if you chose not to write your own multiprecision arithmetic :-) ). </p>\n'}, {'answer_id': 34239, 'author': 'Tyler', 'author_id': 3561, 'author_profile': 'https://Stackoverflow.com/users/3561', 'pm_score': 5, 'selected': False, 'text': '<p>The <a href="http://en.wikipedia.org/wiki/Bailey-Borwein-Plouffe_formula" rel="noreferrer">BBP formula</a> allows you to compute the nth digit - in base 2 (or 16) - without having to even bother with the previous n-1 digits first :)</p>\n'}, {'answer_id': 39512, 'author': 'Pat', 'author_id': 238, 'author_profile': 'https://Stackoverflow.com/users/238', 'pm_score': 7, 'selected': False, 'text': '<p>I really like this program, because it approximates π by looking at its own area.</p>\n\n<p>IOCCC 1988 : <a href="http://www0.us.ioccc.org/1988/westley.c" rel="noreferrer">westley.c</a> </p>\n\n<blockquote>\n<pre><code>#define _ -F&lt;00||--F-OO--;\nint F=00,OO=00;main(){F_OO();printf("%1.3f\\n",4.*-F/OO/OO);}F_OO()\n{\n            _-_-_-_\n       _-_-_-_-_-_-_-_-_\n    _-_-_-_-_-_-_-_-_-_-_-_\n  _-_-_-_-_-_-_-_-_-_-_-_-_-_\n _-_-_-_-_-_-_-_-_-_-_-_-_-_-_\n _-_-_-_-_-_-_-_-_-_-_-_-_-_-_\n_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_\n_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_\n_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_\n_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_\n _-_-_-_-_-_-_-_-_-_-_-_-_-_-_\n _-_-_-_-_-_-_-_-_-_-_-_-_-_-_\n  _-_-_-_-_-_-_-_-_-_-_-_-_-_\n    _-_-_-_-_-_-_-_-_-_-_-_\n        _-_-_-_-_-_-_-_\n            _-_-_-_\n}\n</code></pre>\n</blockquote>\n'}, {'answer_id': 85798, 'author': 'Brad Gilbert', 'author_id': 1337, 'author_profile': 'https://Stackoverflow.com/users/1337', 'pm_score': 4, 'selected': False, 'text': '<h2>Calculate PI at compile-time with D.</h2>\n\n<p>( Copied from <a href="http://www.dsource.org/projects/ddl/browser/trunk/meta/demo/calcpi.d" rel="noreferrer">DSource.org</a> )</p>\n\n<pre class="lang-d prettyprint-override"><code>/** Calculate pi at compile time\n *\n * Compile with dmd -c pi.d\n */\nmodule calcpi;\n\nimport meta.math;\nimport meta.conv;\n\n/** real evaluateSeries!(real x, real metafunction!(real y, int n) term)\n *\n * Evaluate a power series at compile time.\n *\n * Given a metafunction of the form\n *  real term!(real y, int n),\n * which gives the nth term of a convergent series at the point y\n * (where the first term is n==1), and a real number x,\n * this metafunction calculates the infinite sum at the point x\n * by adding terms until the sum doesn\'t change any more.\n */\ntemplate evaluateSeries(real x, alias term, int n=1, real sumsofar=0.0)\n{\n  static if (n&gt;1 &amp;&amp; sumsofar == sumsofar + term!(x, n+1)) {\n     const real evaluateSeries = sumsofar;\n  } else {\n     const real evaluateSeries = evaluateSeries!(x, term, n+1, sumsofar + term!(x, n));\n  }\n}\n\n/*** Calculate atan(x) at compile time.\n *\n * Uses the Maclaurin formula\n *  atan(z) = z - z^3/3 + Z^5/5 - Z^7/7 + ...\n */\ntemplate atan(real z)\n{\n    const real atan = evaluateSeries!(z, atanTerm);\n}\n\ntemplate atanTerm(real x, int n)\n{\n    const real atanTerm =  (n &amp; 1 ? 1 : -1) * pow!(x, 2*n-1)/(2*n-1);\n}\n\n/// Machin\'s formula for pi\n/// pi/4 = 4 atan(1/5) - atan(1/239).\npragma(msg, "PI = " ~ fcvt!(4.0 * (4*atan!(1/5.0) - atan!(1/239.0))) );\n</code></pre>\n'}, {'answer_id': 164687, 'author': 'Andrea Ambu', 'author_id': 21384, 'author_profile': 'https://Stackoverflow.com/users/21384', 'pm_score': 5, 'selected': False, 'text': '<p>This is a "classic" method, very easy to implement.\nThis implementation in python (not the fastest language) does it:</p>\n\n<pre class="lang-python prettyprint-override"><code>from math import pi\nfrom time import time\n\n\nprecision = 10**6 # higher value -&gt; higher precision\n                  # lower  value -&gt; higher speed\n\nt = time()\n\ncalc = 0\nfor k in xrange(0, precision):\n    calc += ((-1)**k) / (2*k+1.)\ncalc *= 4. # this is just a little optimization\n\nt = time()-t\n\nprint "Calculated: %.40f" % calc\nprint "Constant pi: %.40f" % pi\nprint "Difference: %.40f" % abs(calc-pi)\nprint "Time elapsed: %s" % repr(t)\n</code></pre>\n\n<p>You can find more information <a href="http://functions.wolfram.com/Constants/Pi/02/" rel="nofollow noreferrer">here</a>.</p>\n\n<p>Anyway, the fastest way to get a precise as-much-as-you-want value of pi in python is:</p>\n\n<pre class="lang-python prettyprint-override"><code>from gmpy import pi\nprint pi(3000) # the rule is the same as \n               # the precision on the previous code\n</code></pre>\n\n<p>Here is the piece of source for the gmpy pi method, I don\'t think the code is as useful as the comment in this case:</p>\n\n<pre class="lang-c prettyprint-override"><code>static char doc_pi[]="\\\npi(n): returns pi with n bits of precision in an mpf object\\n\\\n";\n\n/* This function was originally from netlib, package bmp, by\n * Richard P. Brent. Paulo Cesar Pereira de Andrade converted\n * it to C and used it in his LISP interpreter.\n *\n * Original comments:\n * \n *   sets mp pi = 3.14159... to the available precision.\n *   uses the gauss-legendre algorithm.\n *   this method requires time o(ln(t)m(t)), so it is slower\n *   than mppi if m(t) = o(t**2), but would be faster for\n *   large t if a faster multiplication algorithm were used\n *   (see comments in mpmul).\n *   for a description of the method, see - multiple-precision\n *   zero-finding and the complexity of elementary function\n *   evaluation (by r. p. brent), in analytic computational\n *   complexity (edited by j. f. traub), academic press, 1976, 151-176.\n *   rounding options not implemented, no guard digits used.\n*/\nstatic PyObject *\nPygmpy_pi(PyObject *self, PyObject *args)\n{\n    PympfObject *pi;\n    int precision;\n    mpf_t r_i2, r_i3, r_i4;\n    mpf_t ix;\n\n    ONE_ARG("pi", "i", &amp;precision);\n    if(!(pi = Pympf_new(precision))) {\n        return NULL;\n    }\n\n    mpf_set_si(pi-&gt;f, 1);\n\n    mpf_init(ix);\n    mpf_set_ui(ix, 1);\n\n    mpf_init2(r_i2, precision);\n\n    mpf_init2(r_i3, precision);\n    mpf_set_d(r_i3, 0.25);\n\n    mpf_init2(r_i4, precision);\n    mpf_set_d(r_i4, 0.5);\n    mpf_sqrt(r_i4, r_i4);\n\n    for (;;) {\n        mpf_set(r_i2, pi-&gt;f);\n        mpf_add(pi-&gt;f, pi-&gt;f, r_i4);\n        mpf_div_ui(pi-&gt;f, pi-&gt;f, 2);\n        mpf_mul(r_i4, r_i2, r_i4);\n        mpf_sub(r_i2, pi-&gt;f, r_i2);\n        mpf_mul(r_i2, r_i2, r_i2);\n        mpf_mul(r_i2, r_i2, ix);\n        mpf_sub(r_i3, r_i3, r_i2);\n        mpf_sqrt(r_i4, r_i4);\n        mpf_mul_ui(ix, ix, 2);\n        /* Check for convergence */\n        if (!(mpf_cmp_si(r_i2, 0) &amp;&amp; \n              mpf_get_prec(r_i2) &gt;= (unsigned)precision)) {\n            mpf_mul(pi-&gt;f, pi-&gt;f, r_i4);\n            mpf_div(pi-&gt;f, pi-&gt;f, r_i3);\n            break;\n        }\n    }\n\n    mpf_clear(ix);\n    mpf_clear(r_i2);\n    mpf_clear(r_i3);\n    mpf_clear(r_i4);\n\n    return (PyObject*)pi;\n}\n</code></pre>\n\n<hr>\n\n<p><strong>EDIT:</strong> I had some problems with cut and paste and indentation, you can find the source <a href="http://code.google.com/p/gmpy/source/browse/branches/aleax-sandbox/src/gmpy.c" rel="nofollow noreferrer">here</a>.</p>\n'}, {'answer_id': 436447, 'author': 'JosephStyons', 'author_id': 672, 'author_profile': 'https://Stackoverflow.com/users/672', 'pm_score': 4, 'selected': False, 'text': '<p>This version (in Delphi) is nothing special, but it is at least faster than <a href="http://blogs.codegear.com/nickhodges/2009/01/09/39174" rel="nofollow noreferrer">the version Nick Hodge posted on his blog</a> :).  On my machine, it takes about 16 seconds to do a billion iterations, giving a value of <strong>3.14159265</strong>25879 (the accurate part is in bold).</p>\n\n<pre class="lang-pascal prettyprint-override"><code>program calcpi;\n\n{$APPTYPE CONSOLE}\n\nuses\n  SysUtils;\n\nvar\n  start, finish: TDateTime;\n\nfunction CalculatePi(iterations: integer): double;\nvar\n  numerator, denominator, i: integer;\n  sum: double;\nbegin\n  {\n  PI may be approximated with this formula:\n  4 * (1 - 1/3 + 1/5 - 1/7 + 1/9 - 1/11 .......)\n  //}\n  numerator := 1;\n  denominator := 1;\n  sum := 0;\n  for i := 1 to iterations do begin\n    sum := sum + (numerator/denominator);\n    denominator := denominator + 2;\n    numerator := -numerator;\n  end;\n  Result := 4 * sum;\nend;\n\nbegin\n  try\n    start := Now;\n    WriteLn(FloatToStr(CalculatePi(StrToInt(ParamStr(1)))));\n    finish := Now;\n    WriteLn(\'Seconds:\' + FormatDateTime(\'hh:mm:ss.zz\',finish-start));\n  except\n    on E:Exception do\n      Writeln(E.Classname, \': \', E.Message);\n  end;\nend.\n</code></pre>\n'}, {'answer_id': 571276, 'author': 'Kristopher Johnson', 'author_id': 1175, 'author_profile': 'https://Stackoverflow.com/users/1175', 'pm_score': 4, 'selected': False, 'text': "<p>Back in the old days, with small word sizes and slow or non-existent floating-point operations, we used to do stuff like this:</p>\n\n<pre><code>/* Return approximation of n * PI; n is integer */\n#define pi_times(n) (((n) * 22) / 7)\n</code></pre>\n\n<p>For applications that don't require a lot of precision (video games, for example), this is very fast and is accurate enough.</p>\n"}, {'answer_id': 592025, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 4, 'selected': False, 'text': '<p>Pi is exactly 3! [Prof. Frink (Simpsons)]</p>\n\n<p>Joke, but here\'s one in C# (.NET-Framework required).</p>\n\n<pre class="lang-cs prettyprint-override"><code>using System;\nusing System.Text;\n\nclass Program {\n    static void Main(string[] args) {\n        int Digits = 100;\n\n        BigNumber x = new BigNumber(Digits);\n        BigNumber y = new BigNumber(Digits);\n        x.ArcTan(16, 5);\n        y.ArcTan(4, 239);\n        x.Subtract(y);\n        string pi = x.ToString();\n        Console.WriteLine(pi);\n    }\n}\n\npublic class BigNumber {\n    private UInt32[] number;\n    private int size;\n    private int maxDigits;\n\n    public BigNumber(int maxDigits) {\n        this.maxDigits = maxDigits;\n        this.size = (int)Math.Ceiling((float)maxDigits * 0.104) + 2;\n        number = new UInt32[size];\n    }\n    public BigNumber(int maxDigits, UInt32 intPart)\n        : this(maxDigits) {\n        number[0] = intPart;\n        for (int i = 1; i &lt; size; i++) {\n            number[i] = 0;\n        }\n    }\n    private void VerifySameSize(BigNumber value) {\n        if (Object.ReferenceEquals(this, value))\n            throw new Exception("BigNumbers cannot operate on themselves");\n        if (value.size != this.size)\n            throw new Exception("BigNumbers must have the same size");\n    }\n\n    public void Add(BigNumber value) {\n        VerifySameSize(value);\n\n        int index = size - 1;\n        while (index &gt;= 0 &amp;&amp; value.number[index] == 0)\n            index--;\n\n        UInt32 carry = 0;\n        while (index &gt;= 0) {\n            UInt64 result = (UInt64)number[index] +\n                            value.number[index] + carry;\n            number[index] = (UInt32)result;\n            if (result &gt;= 0x100000000U)\n                carry = 1;\n            else\n                carry = 0;\n            index--;\n        }\n    }\n    public void Subtract(BigNumber value) {\n        VerifySameSize(value);\n\n        int index = size - 1;\n        while (index &gt;= 0 &amp;&amp; value.number[index] == 0)\n            index--;\n\n        UInt32 borrow = 0;\n        while (index &gt;= 0) {\n            UInt64 result = 0x100000000U + (UInt64)number[index] -\n                            value.number[index] - borrow;\n            number[index] = (UInt32)result;\n            if (result &gt;= 0x100000000U)\n                borrow = 0;\n            else\n                borrow = 1;\n            index--;\n        }\n    }\n    public void Multiply(UInt32 value) {\n        int index = size - 1;\n        while (index &gt;= 0 &amp;&amp; number[index] == 0)\n            index--;\n\n        UInt32 carry = 0;\n        while (index &gt;= 0) {\n            UInt64 result = (UInt64)number[index] * value + carry;\n            number[index] = (UInt32)result;\n            carry = (UInt32)(result &gt;&gt; 32);\n            index--;\n        }\n    }\n    public void Divide(UInt32 value) {\n        int index = 0;\n        while (index &lt; size &amp;&amp; number[index] == 0)\n            index++;\n\n        UInt32 carry = 0;\n        while (index &lt; size) {\n            UInt64 result = number[index] + ((UInt64)carry &lt;&lt; 32);\n            number[index] = (UInt32)(result / (UInt64)value);\n            carry = (UInt32)(result % (UInt64)value);\n            index++;\n        }\n    }\n    public void Assign(BigNumber value) {\n        VerifySameSize(value);\n        for (int i = 0; i &lt; size; i++) {\n            number[i] = value.number[i];\n        }\n    }\n\n    public override string ToString() {\n        BigNumber temp = new BigNumber(maxDigits);\n        temp.Assign(this);\n\n        StringBuilder sb = new StringBuilder();\n        sb.Append(temp.number[0]);\n        sb.Append(System.Globalization.CultureInfo.CurrentCulture.NumberFormat.CurrencyDecimalSeparator);\n\n        int digitCount = 0;\n        while (digitCount &lt; maxDigits) {\n            temp.number[0] = 0;\n            temp.Multiply(100000);\n            sb.AppendFormat("{0:D5}", temp.number[0]);\n            digitCount += 5;\n        }\n\n        return sb.ToString();\n    }\n    public bool IsZero() {\n        foreach (UInt32 item in number) {\n            if (item != 0)\n                return false;\n        }\n        return true;\n    }\n\n    public void ArcTan(UInt32 multiplicand, UInt32 reciprocal) {\n        BigNumber X = new BigNumber(maxDigits, multiplicand);\n        X.Divide(reciprocal);\n        reciprocal *= reciprocal;\n\n        this.Assign(X);\n\n        BigNumber term = new BigNumber(maxDigits);\n        UInt32 divisor = 1;\n        bool subtractTerm = true;\n        while (true) {\n            X.Divide(reciprocal);\n            term.Assign(X);\n            divisor += 2;\n            term.Divide(divisor);\n            if (term.IsZero())\n                break;\n\n            if (subtractTerm)\n                this.Subtract(term);\n            else\n                this.Add(term);\n            subtractTerm = !subtractTerm;\n        }\n    }\n}\n</code></pre>\n'}, {'answer_id': 622950, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 5, 'selected': False, 'text': '<p>Instead of defining pi as a constant, I always use <code>acos(-1)</code>.</p>\n'}, {'answer_id': 1439914, 'author': 'Daniel C. Sobral', 'author_id': 53013, 'author_profile': 'https://Stackoverflow.com/users/53013', 'pm_score': 4, 'selected': False, 'text': '<p>If you are willing to use an approximation, <code>355 / 113</code> is good for 6 decimal digits, and has the added advantage of being usable with integer expressions. That\'s not as important these days, as "floating point math co-processor" ceased to have any meaning, but it was quite important once.</p>\n'}, {'answer_id': 1947163, 'author': 'jon-hanson', 'author_id': 84538, 'author_profile': 'https://Stackoverflow.com/users/84538', 'pm_score': 6, 'selected': False, 'text': '<p>In the interests of completeness, a C++ template version, which, for an optimised build, will compute an approximation of PI at compile time, and will inline to a single value.</p>\n\n<pre class="lang-c++ prettyprint-override"><code>#include &lt;iostream&gt;\n\ntemplate&lt;int I&gt;\nstruct sign\n{\n    enum {value = (I % 2) == 0 ? 1 : -1};\n};\n\ntemplate&lt;int I, int J&gt;\nstruct pi_calc\n{\n    inline static double value ()\n    {\n        return (pi_calc&lt;I-1, J&gt;::value () + pi_calc&lt;I-1, J+1&gt;::value ()) / 2.0;\n    }\n};\n\ntemplate&lt;int J&gt;\nstruct pi_calc&lt;0, J&gt;\n{\n    inline static double value ()\n    {\n        return (sign&lt;J&gt;::value * 4.0) / (2.0 * J + 1.0) + pi_calc&lt;0, J-1&gt;::value ();\n    }\n};\n\n\ntemplate&lt;&gt;\nstruct pi_calc&lt;0, 0&gt;\n{\n    inline static double value ()\n    {\n        return 4.0;\n    }\n};\n\ntemplate&lt;int I&gt;\nstruct pi\n{\n    inline static double value ()\n    {\n        return pi_calc&lt;I, I&gt;::value ();\n    }\n};\n\nint main ()\n{\n    std::cout.precision (12);\n\n    const double pi_value = pi&lt;10&gt;::value ();\n\n    std::cout &lt;&lt; "pi ~ " &lt;&lt; pi_value &lt;&lt; std::endl;\n\n    return 0;\n}\n</code></pre>\n\n<p>Note for I > 10, optimised builds can be slow, likewise for non-optimised runs. For 12 iterations I believe there are around 80k calls to value() (in the absence of memoisation).</p>\n'}, {'answer_id': 1949194, 'author': 'Seth', 'author_id': 65295, 'author_profile': 'https://Stackoverflow.com/users/65295', 'pm_score': 4, 'selected': False, 'text': '<p>If you want to <em>compute</em> an approximation of the value of π (for some reason), you should try a binary extraction algorithm. <a href="http://en.wikipedia.org/wiki/Bellard%27s_formula" rel="noreferrer">Bellard\'s</a> improvement of <a href="http://en.wikipedia.org/wiki/Bailey%E2%80%93Borwein%E2%80%93Plouffe_formula" rel="noreferrer">BBP</a> gives does PI in O(N^2). </p>\n\n<hr>\n\n<p>If you want to <em>obtain</em> an approximation of the value of π to do calculations, then: </p>\n\n<pre><code>PI = 3.141592654\n</code></pre>\n\n<p>Granted, that\'s only an approximation, and not entirely accurate. It\'s off by a little more than 0.00000000004102. (four ten-trillionths, about <sup>4</sup>/<sub>10,000,000,000</sub>).</p>\n\n<hr>\n\n<p>If you want to do <em>math</em> with π, then get yourself a pencil and paper or a computer algebra package, and use π\'s exact value, π. </p>\n\n<p>If you really want a formula, this one is fun: </p>\n\n<h2>π = -<em>i</em> ln(-1)</h2>\n'}, {'answer_id': 2350024, 'author': 'qwerty01', 'author_id': 282776, 'author_profile': 'https://Stackoverflow.com/users/282776', 'pm_score': 4, 'selected': False, 'text': "<p>With doubles:</p>\n\n<pre><code>4.0 * (4.0 * Math.Atan(0.2) - Math.Atan(1.0 / 239.0))\n</code></pre>\n\n<p>This will be accurate up to 14 decimal places, enough to fill a double (the inaccuracy is probably because the rest of the decimals in the arc tangents are truncated).</p>\n\n<p>Also Seth, it's 3.14159265358979323846<b>3</b>, not 64.</p>\n"}, {'answer_id': 4905303, 'author': 'NihilistDandy', 'author_id': 604108, 'author_profile': 'https://Stackoverflow.com/users/604108', 'pm_score': 4, 'selected': False, 'text': '<p>Use the Machin-like formula </p>\n\n<pre><code>176 * arctan (1/57) + 28 * arctan (1/239) - 48 * arctan (1/682) + 96 * arctan(1/12943) \n\n[; \\left( 176 \\arctan \\frac{1}{57} + 28 \\arctan \\frac{1}{239} - 48 \\arctan \\frac{1}{682} + 96 \\arctan \\frac{1}{12943}\\right) ;], for you TeX the World people.\n</code></pre>\n\n<p>Implemented in Scheme, for instance: </p>\n\n<p><code>(+ (- (+ (* 176 (atan (/ 1 57))) (* 28 (atan (/ 1 239)))) (* 48 (atan (/ 1 682)))) (* 96 (atan (/ 1 12943))))</code></p>\n'}, {'answer_id': 7924123, 'author': 'Tilo', 'author_id': 677684, 'author_profile': 'https://Stackoverflow.com/users/677684', 'pm_score': 5, 'selected': False, 'text': '<p>The following answers <strong>precisely how to do this in the fastest possible way -- with the least computing effort</strong>. Even if you don\'t like the answer, you have to admit that it is indeed the fastest way to get the value of PI.</p>\n<p>The <strong>FASTEST</strong> way to get the value of Pi is:</p>\n<ol>\n<li>chose your favourite programming language</li>\n<li>load its Math library</li>\n<li>and find that Pi is already defined there -- ready for use!</li>\n</ol>\n<p>In case you don\'t have a Math library at hand..</p>\n<p>The <strong>SECOND FASTEST</strong> way (more universal solution) is:</p>\n<p>look up Pi on the Internet, e.g. here:</p>\n<p><a href="http://www.eveandersson.com/pi/digits/1000000" rel="nofollow noreferrer">http://www.eveandersson.com/pi/digits/1000000</a> (1 million digits .. what\'s your floating point precision?  )</p>\n<p>or here:</p>\n<p><a href="http://3.141592653589793238462643383279502884197169399375105820974944592.com/" rel="nofollow noreferrer">http://3.141592653589793238462643383279502884197169399375105820974944592.com/</a></p>\n<p>or here:</p>\n<p><a href="http://en.wikipedia.org/wiki/Pi" rel="nofollow noreferrer">http://en.wikipedia.org/wiki/Pi</a></p>\n<p>It\'s really fast to find the digits you need for whatever precision arithmetic you would like to use, and by defining a constant, you can make sure that you don\'t waste precious CPU time.</p>\n<p>Not only is this a partly humorous answer, but in reality, if anybody would go ahead and compute the value of Pi in a real application .. that would be a pretty big waste of CPU time, wouldn\'t it? At least I don\'t see a real application for trying to re-compute this.</p>\n<p><strong>Also consider</strong> that NASA only uses 15 digits of Pi for calculating interplanetary travel:</p>\n<ul>\n<li>TL;DR: <a href="https://twitter.com/Rainmaker1973/status/1463477499434835968" rel="nofollow noreferrer">https://twitter.com/Rainmaker1973/status/1463477499434835968</a></li>\n<li>JPL Explanation: <a href="https://www.jpl.nasa.gov/edu/news/2016/3/16/how-many-decimals-of-pi-do-we-really-need/" rel="nofollow noreferrer">https://www.jpl.nasa.gov/edu/news/2016/3/16/how-many-decimals-of-pi-do-we-really-need/</a></li>\n</ul>\n<p>Dear Moderator: please note that the OP asked: &quot;Fastest Way to get the value of PI&quot;</p>\n'}, {'answer_id': 44346598, 'author': 'Agnius Vasiliauskas', 'author_id': 380331, 'author_profile': 'https://Stackoverflow.com/users/380331', 'pm_score': 1, 'selected': False, 'text': '<p>Calculating π from circle area :-)</p>\n\n<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">\r\n<div class="snippet-code">\r\n<pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;input id="range" type="range" min="10" max="960" value="10" step="50" oninput="calcPi()"&gt;\r\n&lt;br&gt;\r\n&lt;div id="cont"&gt;&lt;/div&gt;\r\n\r\n&lt;script&gt;\r\nfunction generateCircle(width) {\r\n    var c = width/2;\r\n    var delta = 1.0;\r\n    var str = "";\r\n    var xCount = 0;\r\n    for (var x=0; x &lt;= width; x++) {\r\n        for (var y = 0; y &lt;= width; y++) {\r\n            var d = Math.sqrt((x-c)*(x-c) + (y-c)*(y-c));\r\n            if (d &gt; (width-1)/2) {\r\n                str += \'.\';\r\n            }\r\n            else {\r\n                xCount++;\r\n                str += \'o\';\r\n            }\r\n            str += "&amp;nbsp;" \r\n        }\r\n        str += "\\n";\r\n    }\r\n    var pi = (xCount * 4) / (width * width);\r\n    return [str, pi];\r\n}\r\n\r\nfunction calcPi() {\r\n    var e = document.getElementById("cont");\r\n    var width = document.getElementById("range").value;\r\n    e.innerHTML = "&lt;h4&gt;Generating circle...&lt;/h4&gt;";\r\n    setTimeout(function() {\r\n        var circ = generateCircle(width);\r\n        e.innerHTML  = "&lt;pre&gt;" + "π = " + circ[1].toFixed(2) + "\\n" + circ[0] +"&lt;/pre&gt;";\r\n    }, 200);\r\n}\r\ncalcPi();\r\n&lt;/script&gt;</code></pre>\r\n</div>\r\n</div>\r\n</p>\n'}, {'answer_id': 50907044, 'author': 'Anand Tripathi', 'author_id': 5230702, 'author_profile': 'https://Stackoverflow.com/users/5230702', 'pm_score': 0, 'selected': False, 'text': '<h2>Better Approach</h2>\n\n<p>To get the output of standard constants like <strong>pi</strong> or the standard concepts, we should first go with the builtins methods available in the language that you are using. It will return a value in the fastest and best way. I am using python to run the fastest way to get the value of pi.</p>\n\n<ul>\n<li><strong>pi variable of the math library</strong>. The math library stores the variable pi as a constant.</li>\n</ul>\n\n<p>math_pi.py</p>\n\n<pre><code>import math\nprint math.pi\n</code></pre>\n\n<p>Run the script with time utility of linux <code>/usr/bin/time -v python math_pi.py</code></p>\n\n<p>Output:</p>\n\n<pre><code>Command being timed: "python math_pi.py"\nUser time (seconds): 0.01\nSystem time (seconds): 0.01\nPercent of CPU this job got: 91%\nElapsed (wall clock) time (h:mm:ss or m:ss): 0:00.03\n</code></pre>\n\n<ul>\n<li><strong>Use arc cos method of math</strong></li>\n</ul>\n\n<p>acos_pi.py</p>\n\n<pre><code>import math\nprint math.acos(-1)\n</code></pre>\n\n<p>Run the script with time utility of linux <code>/usr/bin/time -v python acos_pi.py</code></p>\n\n<p>Output:</p>\n\n<pre><code>Command being timed: "python acos_pi.py"\nUser time (seconds): 0.02\nSystem time (seconds): 0.01\nPercent of CPU this job got: 94%\nElapsed (wall clock) time (h:mm:ss or m:ss): 0:00.03\n</code></pre>\n\n<ul>\n<li><strong>use <a href="https://en.wikipedia.org/wiki/Bailey%E2%80%93Borwein%E2%80%93Plouffe_formula" rel="nofollow noreferrer">BBP formula</a></strong></li>\n</ul>\n\n<p>bbp_pi.py</p>\n\n<pre><code>from decimal import Decimal, getcontext\ngetcontext().prec=100\nprint sum(1/Decimal(16)**k * \n          (Decimal(4)/(8*k+1) - \n           Decimal(2)/(8*k+4) - \n           Decimal(1)/(8*k+5) -\n           Decimal(1)/(8*k+6)) for k in range(100))\n</code></pre>\n\n<p>Run the script with time utility of linux <code>/usr/bin/time -v python bbp_pi.py</code></p>\n\n<p>Output:</p>\n\n<pre><code>Command being timed: "python c.py"\nUser time (seconds): 0.05\nSystem time (seconds): 0.01\nPercent of CPU this job got: 98%\nElapsed (wall clock) time (h:mm:ss or m:ss): 0:00.06\n</code></pre>\n\n<p><strong>So the best way is to use builtin methods provided by the language because they are the fastest and best to get the output. In python use math.pi</strong></p>\n'}, {'answer_id': 61670212, 'author': 'paperclip optimizer', 'author_id': 11147804, 'author_profile': 'https://Stackoverflow.com/users/11147804', 'pm_score': 1, 'selected': False, 'text': '<p>The Chudnovsky algorithm is pretty fast if you don\'t mind performing a square root and a couple inverses. It converges to double precision in just 2 iterations.</p>\n\n<pre><code>/*\n    Chudnovsky algorithm for computing PI\n*/\n\n#include &lt;iostream&gt;\n#include &lt;cmath&gt;\nusing namespace std;\n\ndouble calc_PI(int K=2) {\n\n    static const int A = 545140134;\n    static const int B = 13591409;\n    static const int D = 640320;\n\n    const double ID3 = 1./ (double(D)*double(D)*double(D));\n\n    double sum = 0.;\n    double b   = sqrt(ID3);\n    long long int p = 1;\n    long long int a = B;\n\n    sum += double(p) * double(a)* b;\n\n    // 2 iterations enough for double convergence\n    for (int k=1; k&lt;K; ++k) {\n        // A*k + B\n        a += A;\n        // update denominator\n        b *= ID3;\n        // p = (-1)^k 6k! / 3k! k!^3\n        p *= (6*k)*(6*k-1)*(6*k-2)*(6*k-3)*(6*k-4)*(6*k-5);\n        p /= (3*k)*(3*k-1)*(3*k-2) * k*k*k;\n        p = -p;\n\n        sum += double(p) * double(a)* b;\n    }\n\n    return 1./(12*sum);\n}\n\nint main() {\n\n    cout.precision(16);\n    cout.setf(ios::fixed);\n\n    for (int k=1; k&lt;=5; ++k) cout &lt;&lt; "k = " &lt;&lt; k &lt;&lt; "   PI = " &lt;&lt; calc_PI(k) &lt;&lt; endl;\n\n    return 0;\n}\n</code></pre>\n\n<p>Results:</p>\n\n<pre><code>k = 1   PI = 3.1415926535897341\nk = 2   PI = 3.1415926535897931\nk = 3   PI = 3.1415926535897931\nk = 4   PI = 3.1415926535897931\nk = 5   PI = 3.1415926535897931\n</code></pre>\n'}, {'answer_id': 64410809, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 2, 'selected': False, 'text': "<p>Basically the C version of paperclip optimizer's answer, and much more simpilified:</p>\n<pre><code>#include &lt;stdio.h&gt;\n#include &lt;math.h&gt;\n\ndouble calc_PI(int K) {\n    static const int A = 545140134;\n    static const int B = 13591409;\n    static const int D = 640320;\n    const double ID3 = 1.0 / ((double) D * (double) D * (double) D);\n    double sum = 0.0;\n    double b = sqrt(ID3);\n    long long int p = 1;\n    long long int a = B;\n    sum += (double) p * (double) a * b;\n    for (int k = 1; k &lt; K; ++k) {\n        a += A;\n        b *= ID3;\n        p *= (6 * k) * (6 * k - 1) * (6 * k - 2) * (6 * k - 3) * (6 * k - 4) * (6 * k - 5);\n        p /= (3 * k) * (3 * k - 1) * (3 * k - 2) * k * k * k;\n        p = -p;\n        sum += (double) p * (double) a * b;\n    }\n    return 1.0 / (12 * sum);\n}\n\nint main() {\n    for (int k = 1; k &lt;= 5; ++k) {\n        printf(&quot;k = %i, PI = %.16f\\n&quot;, k, calc_PI(k));\n    }\n}\n</code></pre>\n<p>But for more simplification, this algorithm takes Chudnovsky's formula, which I can fully simplify if you don't really understand the code.</p>\n<p>Summary: We will get a number from 1 to 5 and add it in to a function we will use to get PI. Then 3 numbers are given to you: 545140134 (A), 13591409 (B), 640320 (D). Then we will use D as a <code>double</code> multiplying itself 3 times into another <code>double</code> (ID3). We will then take the square root of ID3 into another <code>double</code> (b) and assign 2 numbers: 1 (p), the value of B (a). <strong>Take note that C is case-insensitive.</strong> Then a <code>double</code> (sum) will be created by multiplying the value's of p, a and b, all in <code>double</code>s. Then a loop up until the number given for the function will start and add up A's value to a, b's value gets multiplied by ID3, p's value will be multiplied by multiple values that I hope you can understand and also gets divided by multiple values as well. The sum will add up by p, a and b once again and the loop will repeat until the value of the loop's number is greater or equal to 5. Later, the sum is multiplied by 12 and returned by the function giving us the result of PI.</p>\n<p>Okay, that was long, but I guess you will understand it...</p>\n"}, {'answer_id': 69610755, 'author': 'Rajanand', 'author_id': 16425812, 'author_profile': 'https://Stackoverflow.com/users/16425812', 'pm_score': 1, 'selected': False, 'text': '<p>I think the value of pi is the ratio between the circumference and radius of the circle.</p>\n<p>It can be simply achieved by a regular math calculation</p>\n'}, {'answer_id': 73777598, 'author': 'Andy Richter', 'author_id': 6262481, 'author_profile': 'https://Stackoverflow.com/users/6262481', 'pm_score': 0, 'selected': False, 'text': '<h2>Faster than GMPY2 and MPmath Built-ins: A Billion in 45 minutes:</h2>\n<hr />\n<p>I tried several ways; Manchin, AGM and Chudnovsky Bros.  Chudnovsky with Binary Split was the fastest:<br />\nMy github : <a href="https://github.com/Overboard-code/Pi-Pourri" rel="nofollow noreferrer">https://github.com/Overboard-code/Pi-Pourri</a></p>\n<p>My Binary Split Chudnovsky is about <strong>twice</strong> the speed of the builtin gmpy2.const_pi(). MPmath.mp.pi() took 50 minutes for a billion, so it was almost as fast as the Chudnovsky.</p>\n<p>I would greatly appreciate performance tips as well.  I am not sure my code is perfect. It is 100% accurate (all formula agree to 100 million) but maybe could be faster?</p>\n<p>I tried gmpy2.const_pi() to 100 million digits and it took 300 seconds vs. 150 seconds for the Chudnovsky on the same machine. pi.txt and pi2.txt were the same.</p>\n<p>I got to a billion digits on my old i7 16GB laptop in less than an hour.</p>\n<p>Here is a snippet of the fastest of the 12 methods I tried:</p>\n<pre><code>class PiChudnovsky:\n    &quot;&quot;&quot;Version of Chudnovsky Bros using Binary Splitting \n        So far this is the winner for fastest time to a million digits on my older intel i7\n    &quot;&quot;&quot;\n    A = mpz(13591409)\n    B = mpz(545140134)\n    C = mpz(640320)\n    D = mpz(426880)\n    E = mpz(10005)\n    C3_24  = pow(C, mpz(3)) // mpz(24)\n    #DIGITS_PER_TERM = math.log(53360 ** 3) / math.log(10)  #=&gt; 14.181647462725476\n    DIGITS_PER_TERM = 14.181647462725476\n    MMILL = mpz(1000000)\n\n    def __init__(self,ndigits):\n        &quot;&quot;&quot; Initialization\n        :param int ndigits: digits of PI computation\n        &quot;&quot;&quot;\n        self.ndigits = ndigits\n        self.n      = mpz(self.ndigits // self.DIGITS_PER_TERM + 1)\n        self.prec   = mpz((self.ndigits + 1) * LOG2_10)\n        self.one_sq = pow(mpz(10),mpz(2 * ndigits))\n        self.sqrt_c = isqrt(self.E * self.one_sq)\n        self.iters  = mpz(0)\n        self.start_time = 0\n\n    def compute(self):\n        &quot;&quot;&quot; Computation &quot;&quot;&quot;\n        try:\n            self.start_time = time.time()\n            logging.debug(&quot;Starting {} formula to {:,} decimal places&quot;\n                .format(name,ndigits) )\n            __, q, t = self.__bs(mpz(0), self.n)  # p is just for recursion\n            pi = (q * self.D * self.sqrt_c) // t\n            logging.debug(\'{} calulation Done! {:,} iterations and {:.2f} seconds.\'\n                .format( name, int(self.iters),time.time() - self.start_time))\n            get_context().precision= int((self.ndigits+10) * LOG2_10)\n            pi_s = pi.digits() # digits() gmpy2 creates a string \n            pi_o = pi_s[:1] + &quot;.&quot; + pi_s[1:]\n            return pi_o,int(self.iters),time.time() - self.start_time\n        except Exception as e:\n            print (e.message, e.args)\n            raise\n\n    def __bs(self, a, b):\n        &quot;&quot;&quot; PQT computation by BSA(= Binary Splitting Algorithm)\n        :param int a: positive integer\n        :param int b: positive integer\n        :return list [int p_ab, int q_ab, int t_ab]\n        &quot;&quot;&quot;\n        try:\n            self.iters += mpz(1)\n            if self.iters % self.MMILL  == mpz(0):\n                logging.debug(\'Chudnovsky ... {:,} iterations and {:.2f} seconds.\'\n                    .format( int(self.iters),time.time() - self.start_time))\n            if a + mpz(1) == b:\n                if a == mpz(0):\n                    p_ab = q_ab = mpz(1)\n                else:\n                    p_ab = mpz((mpz(6) * a - mpz(5)) * (mpz(2) * a - mpz(1)) * (mpz(6) * a - mpz(1)))\n                    q_ab = pow(a,mpz(3)) * self.C3_24\n                t_ab = p_ab * (self.A + self.B * a)\n                if a &amp; 1:\n                    t_ab *= mpz(-1)\n            else:\n                m = (a + b) // mpz(2)\n                p_am, q_am, t_am = self.__bs(a, m)\n                p_mb, q_mb, t_mb = self.__bs(m, b)\n                p_ab = p_am * p_mb\n                q_ab = q_am * q_mb\n                t_ab = q_mb * t_am + p_am * t_mb\n            return [p_ab, q_ab, t_ab]\n        except Exception as e:\n            print (e.message, e.args)\n            raise\n</code></pre>\n<p>Here is the output of 1,000,000,000 digits less than 45 minutes:</p>\n<pre><code>python pi-pourri.py -v -d 1,000,000,000 -a 10 \n\n[INFO] 2022-10-03 09:22:51,860 &lt;module&gt;: MainProcess Computing π to 1,000,000,000 digits.\n[DEBUG] 2022-10-03 09:25:00,543 compute: MainProcess Starting   Chudnovsky brothers  1988 \n    π = (Q(0, N) / 12T(0, N) + 12AQ(0, N))**(C**(3/2))\n formula to 1,000,000,000 decimal places\n[DEBUG] 2022-10-03 09:25:04,995 __bs: MainProcess Chudnovsky ... 1,000,000 iterations and 4.45 seconds.\n[DEBUG] 2022-10-03 09:25:10,836 __bs: MainProcess Chudnovsky ... 2,000,000 iterations and 10.29 seconds.\n[DEBUG] 2022-10-03 09:25:18,227 __bs: MainProcess Chudnovsky ... 3,000,000 iterations and 17.68 seconds.\n[DEBUG] 2022-10-03 09:25:24,512 __bs: MainProcess Chudnovsky ... 4,000,000 iterations and 23.97 seconds.\n[DEBUG] 2022-10-03 09:25:35,670 __bs: MainProcess Chudnovsky ... 5,000,000 iterations and 35.13 seconds.\n[DEBUG] 2022-10-03 09:25:41,376 __bs: MainProcess Chudnovsky ... 6,000,000 iterations and 40.83 seconds.\n[DEBUG] 2022-10-03 09:25:49,238 __bs: MainProcess Chudnovsky ... 7,000,000 iterations and 48.69 seconds.\n[DEBUG] 2022-10-03 09:25:55,646 __bs: MainProcess Chudnovsky ... 8,000,000 iterations and 55.10 seconds.\n[DEBUG] 2022-10-03 09:26:15,043 __bs: MainProcess Chudnovsky ... 9,000,000 iterations and 74.50 seconds.\n[DEBUG] 2022-10-03 09:26:21,437 __bs: MainProcess Chudnovsky ... 10,000,000 iterations and 80.89 seconds.\n[DEBUG] 2022-10-03 09:26:26,587 __bs: MainProcess Chudnovsky ... 11,000,000 iterations and 86.04 seconds.\n[DEBUG] 2022-10-03 09:26:34,777 __bs: MainProcess Chudnovsky ... 12,000,000 iterations and 94.23 seconds.\n[DEBUG] 2022-10-03 09:26:41,231 __bs: MainProcess Chudnovsky ... 13,000,000 iterations and 100.69 seconds.\n[DEBUG] 2022-10-03 09:26:52,972 __bs: MainProcess Chudnovsky ... 14,000,000 iterations and 112.43 seconds.\n[DEBUG] 2022-10-03 09:26:59,517 __bs: MainProcess Chudnovsky ... 15,000,000 iterations and 118.97 seconds.\n[DEBUG] 2022-10-03 09:27:07,932 __bs: MainProcess Chudnovsky ... 16,000,000 iterations and 127.39 seconds.\n[DEBUG] 2022-10-03 09:27:14,036 __bs: MainProcess Chudnovsky ... 17,000,000 iterations and 133.49 seconds.\n[DEBUG] 2022-10-03 09:27:51,629 __bs: MainProcess Chudnovsky ... 18,000,000 iterations and 171.09 seconds.\n[DEBUG] 2022-10-03 09:27:58,176 __bs: MainProcess Chudnovsky ... 19,000,000 iterations and 177.63 seconds.\n[DEBUG] 2022-10-03 09:28:06,704 __bs: MainProcess Chudnovsky ... 20,000,000 iterations and 186.16 seconds.\n[DEBUG] 2022-10-03 09:28:13,376 __bs: MainProcess Chudnovsky ... 21,000,000 iterations and 192.83 seconds.\n[DEBUG] 2022-10-03 09:28:18,737 __bs: MainProcess Chudnovsky ... 22,000,000 iterations and 198.19 seconds.\n[DEBUG] 2022-10-03 09:28:31,095 __bs: MainProcess Chudnovsky ... 23,000,000 iterations and 210.55 seconds.\n[DEBUG] 2022-10-03 09:28:37,789 __bs: MainProcess Chudnovsky ... 24,000,000 iterations and 217.25 seconds.\n[DEBUG] 2022-10-03 09:28:46,171 __bs: MainProcess Chudnovsky ... 25,000,000 iterations and 225.63 seconds.\n[DEBUG] 2022-10-03 09:28:52,933 __bs: MainProcess Chudnovsky ... 26,000,000 iterations and 232.39 seconds.\n[DEBUG] 2022-10-03 09:29:13,524 __bs: MainProcess Chudnovsky ... 27,000,000 iterations and 252.98 seconds.\n[DEBUG] 2022-10-03 09:29:19,676 __bs: MainProcess Chudnovsky ... 28,000,000 iterations and 259.13 seconds.\n[DEBUG] 2022-10-03 09:29:28,196 __bs: MainProcess Chudnovsky ... 29,000,000 iterations and 267.65 seconds.\n[DEBUG] 2022-10-03 09:29:34,720 __bs: MainProcess Chudnovsky ... 30,000,000 iterations and 274.18 seconds.\n[DEBUG] 2022-10-03 09:29:47,075 __bs: MainProcess Chudnovsky ... 31,000,000 iterations and 286.53 seconds.\n[DEBUG] 2022-10-03 09:29:53,746 __bs: MainProcess Chudnovsky ... 32,000,000 iterations and 293.20 seconds.\n[DEBUG] 2022-10-03 09:29:59,099 __bs: MainProcess Chudnovsky ... 33,000,000 iterations and 298.56 seconds.\n[DEBUG] 2022-10-03 09:30:07,511 __bs: MainProcess Chudnovsky ... 34,000,000 iterations and 306.97 seconds.\n[DEBUG] 2022-10-03 09:30:14,279 __bs: MainProcess Chudnovsky ... 35,000,000 iterations and 313.74 seconds.\n[DEBUG] 2022-10-03 09:31:31,710 __bs: MainProcess Chudnovsky ... 36,000,000 iterations and 391.17 seconds.\n[DEBUG] 2022-10-03 09:31:38,454 __bs: MainProcess Chudnovsky ... 37,000,000 iterations and 397.91 seconds.\n[DEBUG] 2022-10-03 09:31:46,437 __bs: MainProcess Chudnovsky ... 38,000,000 iterations and 405.89 seconds.\n[DEBUG] 2022-10-03 09:31:53,285 __bs: MainProcess Chudnovsky ... 39,000,000 iterations and 412.74 seconds.\n[DEBUG] 2022-10-03 09:32:05,602 __bs: MainProcess Chudnovsky ... 40,000,000 iterations and 425.06 seconds.\n[DEBUG] 2022-10-03 09:32:12,220 __bs: MainProcess Chudnovsky ... 41,000,000 iterations and 431.68 seconds.\n[DEBUG] 2022-10-03 09:32:20,708 __bs: MainProcess Chudnovsky ... 42,000,000 iterations and 440.17 seconds.\n[DEBUG] 2022-10-03 09:32:27,552 __bs: MainProcess Chudnovsky ... 43,000,000 iterations and 447.01 seconds.\n[DEBUG] 2022-10-03 09:32:32,986 __bs: MainProcess Chudnovsky ... 44,000,000 iterations and 452.44 seconds.\n[DEBUG] 2022-10-03 09:32:53,904 __bs: MainProcess Chudnovsky ... 45,000,000 iterations and 473.36 seconds.\n[DEBUG] 2022-10-03 09:33:00,832 __bs: MainProcess Chudnovsky ... 46,000,000 iterations and 480.29 seconds.\n[DEBUG] 2022-10-03 09:33:09,198 __bs: MainProcess Chudnovsky ... 47,000,000 iterations and 488.66 seconds.\n[DEBUG] 2022-10-03 09:33:16,000 __bs: MainProcess Chudnovsky ... 48,000,000 iterations and 495.46 seconds.\n[DEBUG] 2022-10-03 09:33:27,921 __bs: MainProcess Chudnovsky ... 49,000,000 iterations and 507.38 seconds.\n[DEBUG] 2022-10-03 09:33:34,778 __bs: MainProcess Chudnovsky ... 50,000,000 iterations and 514.24 seconds.\n[DEBUG] 2022-10-03 09:33:43,298 __bs: MainProcess Chudnovsky ... 51,000,000 iterations and 522.76 seconds.\n[DEBUG] 2022-10-03 09:33:49,959 __bs: MainProcess Chudnovsky ... 52,000,000 iterations and 529.42 seconds.\n[DEBUG] 2022-10-03 09:34:29,294 __bs: MainProcess Chudnovsky ... 53,000,000 iterations and 568.75 seconds.\n[DEBUG] 2022-10-03 09:34:36,176 __bs: MainProcess Chudnovsky ... 54,000,000 iterations and 575.63 seconds.\n[DEBUG] 2022-10-03 09:34:41,576 __bs: MainProcess Chudnovsky ... 55,000,000 iterations and 581.03 seconds.\n[DEBUG] 2022-10-03 09:34:50,161 __bs: MainProcess Chudnovsky ... 56,000,000 iterations and 589.62 seconds.\n[DEBUG] 2022-10-03 09:34:56,811 __bs: MainProcess Chudnovsky ... 57,000,000 iterations and 596.27 seconds.\n[DEBUG] 2022-10-03 09:35:09,382 __bs: MainProcess Chudnovsky ... 58,000,000 iterations and 608.84 seconds.\n[DEBUG] 2022-10-03 09:35:16,206 __bs: MainProcess Chudnovsky ... 59,000,000 iterations and 615.66 seconds.\n[DEBUG] 2022-10-03 09:35:24,295 __bs: MainProcess Chudnovsky ... 60,000,000 iterations and 623.75 seconds.\n[DEBUG] 2022-10-03 09:35:31,095 __bs: MainProcess Chudnovsky ... 61,000,000 iterations and 630.55 seconds.\n[DEBUG] 2022-10-03 09:35:52,139 __bs: MainProcess Chudnovsky ... 62,000,000 iterations and 651.60 seconds.\n[DEBUG] 2022-10-03 09:35:58,781 __bs: MainProcess Chudnovsky ... 63,000,000 iterations and 658.24 seconds.\n[DEBUG] 2022-10-03 09:36:07,399 __bs: MainProcess Chudnovsky ... 64,000,000 iterations and 666.86 seconds.\n[DEBUG] 2022-10-03 09:36:12,847 __bs: MainProcess Chudnovsky ... 65,000,000 iterations and 672.30 seconds.\n[DEBUG] 2022-10-03 09:36:19,763 __bs: MainProcess Chudnovsky ... 66,000,000 iterations and 679.22 seconds.\n[DEBUG] 2022-10-03 09:36:32,351 __bs: MainProcess Chudnovsky ... 67,000,000 iterations and 691.81 seconds.\n[DEBUG] 2022-10-03 09:36:39,078 __bs: MainProcess Chudnovsky ... 68,000,000 iterations and 698.53 seconds.\n[DEBUG] 2022-10-03 09:36:47,830 __bs: MainProcess Chudnovsky ... 69,000,000 iterations and 707.29 seconds.\n[DEBUG] 2022-10-03 09:36:54,701 __bs: MainProcess Chudnovsky ... 70,000,000 iterations and 714.16 seconds.\n[DEBUG] 2022-10-03 09:39:39,357 __bs: MainProcess Chudnovsky ... 71,000,000 iterations and 878.81 seconds.\n[DEBUG] 2022-10-03 09:39:46,199 __bs: MainProcess Chudnovsky ... 72,000,000 iterations and 885.66 seconds.\n[DEBUG] 2022-10-03 09:39:54,956 __bs: MainProcess Chudnovsky ... 73,000,000 iterations and 894.41 seconds.\n[DEBUG] 2022-10-03 09:40:01,639 __bs: MainProcess Chudnovsky ... 74,000,000 iterations and 901.10 seconds.\n[DEBUG] 2022-10-03 09:40:14,219 __bs: MainProcess Chudnovsky ... 75,000,000 iterations and 913.68 seconds.\n[DEBUG] 2022-10-03 09:40:19,680 __bs: MainProcess Chudnovsky ... 76,000,000 iterations and 919.14 seconds.\n[DEBUG] 2022-10-03 09:40:26,625 __bs: MainProcess Chudnovsky ... 77,000,000 iterations and 926.08 seconds.\n[DEBUG] 2022-10-03 09:40:35,212 __bs: MainProcess Chudnovsky ... 78,000,000 iterations and 934.67 seconds.\n[DEBUG] 2022-10-03 09:40:41,914 __bs: MainProcess Chudnovsky ... 79,000,000 iterations and 941.37 seconds.\n[DEBUG] 2022-10-03 09:41:03,218 __bs: MainProcess Chudnovsky ... 80,000,000 iterations and 962.68 seconds.\n[DEBUG] 2022-10-03 09:41:10,213 __bs: MainProcess Chudnovsky ... 81,000,000 iterations and 969.67 seconds.\n[DEBUG] 2022-10-03 09:41:18,344 __bs: MainProcess Chudnovsky ... 82,000,000 iterations and 977.80 seconds.\n[DEBUG] 2022-10-03 09:41:25,261 __bs: MainProcess Chudnovsky ... 83,000,000 iterations and 984.72 seconds.\n[DEBUG] 2022-10-03 09:41:37,663 __bs: MainProcess Chudnovsky ... 84,000,000 iterations and 997.12 seconds.\n[DEBUG] 2022-10-03 09:41:44,680 __bs: MainProcess Chudnovsky ... 85,000,000 iterations and 1004.14 seconds.\n[DEBUG] 2022-10-03 09:41:53,411 __bs: MainProcess Chudnovsky ... 86,000,000 iterations and 1012.87 seconds.\n[DEBUG] 2022-10-03 09:41:58,926 __bs: MainProcess Chudnovsky ... 87,000,000 iterations and 1018.38 seconds.\n[DEBUG] 2022-10-03 09:42:05,858 __bs: MainProcess Chudnovsky ... 88,000,000 iterations and 1025.32 seconds.\n[DEBUG] 2022-10-03 09:42:46,163 __bs: MainProcess Chudnovsky ... 89,000,000 iterations and 1065.62 seconds.\n[DEBUG] 2022-10-03 09:42:53,054 __bs: MainProcess Chudnovsky ... 90,000,000 iterations and 1072.51 seconds.\n[DEBUG] 2022-10-03 09:43:02,030 __bs: MainProcess Chudnovsky ... 91,000,000 iterations and 1081.49 seconds.\n[DEBUG] 2022-10-03 09:43:09,192 __bs: MainProcess Chudnovsky ... 92,000,000 iterations and 1088.65 seconds.\n[DEBUG] 2022-10-03 09:43:21,533 __bs: MainProcess Chudnovsky ... 93,000,000 iterations and 1100.99 seconds.\n[DEBUG] 2022-10-03 09:43:28,643 __bs: MainProcess Chudnovsky ... 94,000,000 iterations and 1108.10 seconds.\n[DEBUG] 2022-10-03 09:43:37,372 __bs: MainProcess Chudnovsky ... 95,000,000 iterations and 1116.83 seconds.\n[DEBUG] 2022-10-03 09:43:44,558 __bs: MainProcess Chudnovsky ... 96,000,000 iterations and 1124.02 seconds.\n[DEBUG] 2022-10-03 09:44:06,555 __bs: MainProcess Chudnovsky ... 97,000,000 iterations and 1146.01 seconds.\n[DEBUG] 2022-10-03 09:44:12,220 __bs: MainProcess Chudnovsky ... 98,000,000 iterations and 1151.68 seconds.\n[DEBUG] 2022-10-03 09:44:19,278 __bs: MainProcess Chudnovsky ... 99,000,000 iterations and 1158.74 seconds.\n[DEBUG] 2022-10-03 09:44:28,323 __bs: MainProcess Chudnovsky ... 100,000,000 iterations and 1167.78 seconds.\n[DEBUG] 2022-10-03 09:44:35,211 __bs: MainProcess Chudnovsky ... 101,000,000 iterations and 1174.67 seconds.\n[DEBUG] 2022-10-03 09:44:48,331 __bs: MainProcess Chudnovsky ... 102,000,000 iterations and 1187.79 seconds.\n[DEBUG] 2022-10-03 09:44:54,835 __bs: MainProcess Chudnovsky ... 103,000,000 iterations and 1194.29 seconds.\n[DEBUG] 2022-10-03 09:45:03,869 __bs: MainProcess Chudnovsky ... 104,000,000 iterations and 1203.33 seconds.\n[DEBUG] 2022-10-03 09:45:10,967 __bs: MainProcess Chudnovsky ... 105,000,000 iterations and 1210.42 seconds.\n[DEBUG] 2022-10-03 09:46:32,760 __bs: MainProcess Chudnovsky ... 106,000,000 iterations and 1292.22 seconds.\n[DEBUG] 2022-10-03 09:46:39,872 __bs: MainProcess Chudnovsky ... 107,000,000 iterations and 1299.33 seconds.\n[DEBUG] 2022-10-03 09:46:48,948 __bs: MainProcess Chudnovsky ... 108,000,000 iterations and 1308.41 seconds.\n[DEBUG] 2022-10-03 09:46:54,611 __bs: MainProcess Chudnovsky ... 109,000,000 iterations and 1314.07 seconds.\n[DEBUG] 2022-10-03 09:47:01,727 __bs: MainProcess Chudnovsky ... 110,000,000 iterations and 1321.18 seconds.\n[DEBUG] 2022-10-03 09:47:14,525 __bs: MainProcess Chudnovsky ... 111,000,000 iterations and 1333.98 seconds.\n[DEBUG] 2022-10-03 09:47:21,682 __bs: MainProcess Chudnovsky ... 112,000,000 iterations and 1341.14 seconds.\n[DEBUG] 2022-10-03 09:47:30,610 __bs: MainProcess Chudnovsky ... 113,000,000 iterations and 1350.07 seconds.\n[DEBUG] 2022-10-03 09:47:37,176 __bs: MainProcess Chudnovsky ... 114,000,000 iterations and 1356.63 seconds.\n[DEBUG] 2022-10-03 09:47:59,642 __bs: MainProcess Chudnovsky ... 115,000,000 iterations and 1379.10 seconds.\n[DEBUG] 2022-10-03 09:48:06,702 __bs: MainProcess Chudnovsky ... 116,000,000 iterations and 1386.16 seconds.\n[DEBUG] 2022-10-03 09:48:15,483 __bs: MainProcess Chudnovsky ... 117,000,000 iterations and 1394.94 seconds.\n[DEBUG] 2022-10-03 09:48:22,537 __bs: MainProcess Chudnovsky ... 118,000,000 iterations and 1401.99 seconds.\n[DEBUG] 2022-10-03 09:48:35,714 __bs: MainProcess Chudnovsky ... 119,000,000 iterations and 1415.17 seconds.\n[DEBUG] 2022-10-03 09:48:41,321 __bs: MainProcess Chudnovsky ... 120,000,000 iterations and 1420.78 seconds.\n[DEBUG] 2022-10-03 09:48:48,408 __bs: MainProcess Chudnovsky ... 121,000,000 iterations and 1427.87 seconds.\n[DEBUG] 2022-10-03 09:48:57,138 __bs: MainProcess Chudnovsky ... 122,000,000 iterations and 1436.60 seconds.\n[DEBUG] 2022-10-03 09:49:04,328 __bs: MainProcess Chudnovsky ... 123,000,000 iterations and 1443.79 seconds.\n[DEBUG] 2022-10-03 09:49:46,274 __bs: MainProcess Chudnovsky ... 124,000,000 iterations and 1485.73 seconds.\n[DEBUG] 2022-10-03 09:49:52,833 __bs: MainProcess Chudnovsky ... 125,000,000 iterations and 1492.29 seconds.\n[DEBUG] 2022-10-03 09:50:01,786 __bs: MainProcess Chudnovsky ... 126,000,000 iterations and 1501.24 seconds.\n[DEBUG] 2022-10-03 09:50:08,975 __bs: MainProcess Chudnovsky ... 127,000,000 iterations and 1508.43 seconds.\n[DEBUG] 2022-10-03 09:50:21,850 __bs: MainProcess Chudnovsky ... 128,000,000 iterations and 1521.31 seconds.\n[DEBUG] 2022-10-03 09:50:28,962 __bs: MainProcess Chudnovsky ... 129,000,000 iterations and 1528.42 seconds.\n[DEBUG] 2022-10-03 09:50:34,594 __bs: MainProcess Chudnovsky ... 130,000,000 iterations and 1534.05 seconds.\n[DEBUG] 2022-10-03 09:50:43,647 __bs: MainProcess Chudnovsky ... 131,000,000 iterations and 1543.10 seconds.\n[DEBUG] 2022-10-03 09:50:50,724 __bs: MainProcess Chudnovsky ... 132,000,000 iterations and 1550.18 seconds.\n[DEBUG] 2022-10-03 09:51:12,742 __bs: MainProcess Chudnovsky ... 133,000,000 iterations and 1572.20 seconds.\n[DEBUG] 2022-10-03 09:51:19,799 __bs: MainProcess Chudnovsky ... 134,000,000 iterations and 1579.26 seconds.\n[DEBUG] 2022-10-03 09:51:28,824 __bs: MainProcess Chudnovsky ... 135,000,000 iterations and 1588.28 seconds.\n[DEBUG] 2022-10-03 09:51:35,324 __bs: MainProcess Chudnovsky ... 136,000,000 iterations and 1594.78 seconds.\n[DEBUG] 2022-10-03 09:51:48,419 __bs: MainProcess Chudnovsky ... 137,000,000 iterations and 1607.88 seconds.\n[DEBUG] 2022-10-03 09:51:55,634 __bs: MainProcess Chudnovsky ... 138,000,000 iterations and 1615.09 seconds.\n[DEBUG] 2022-10-03 09:52:04,435 __bs: MainProcess Chudnovsky ... 139,000,000 iterations and 1623.89 seconds.\n[DEBUG] 2022-10-03 09:52:11,583 __bs: MainProcess Chudnovsky ... 140,000,000 iterations and 1631.04 seconds.\n[DEBUG] 2022-10-03 09:52:17,222 __bs: MainProcess Chudnovsky ... 141,000,000 iterations and 1636.68 seconds.\n[DEBUG] 2022-10-03 10:02:43,939 compute: MainProcess    Chudnovsky brothers  1988 \n    π = (Q(0, N) / 12T(0, N) + 12AQ(0, N))**(C**(3/2))\n calulation Done! 141,027,339 iterations and 2263.39 seconds.\n[INFO] 2022-10-03 10:09:07,119 &lt;module&gt;: MainProcess Last 5 digits of π were 45519 as expected at offset 999,999,995\n[INFO] 2022-10-03 10:09:07,119 &lt;module&gt;: MainProcess Calculated π to 1,000,000,000 digits using a formula of:\n 10     Chudnovsky brothers  1988 \n    π = (Q(0, N) / 12T(0, N) + 12AQ(0, N))**(C**(3/2))\n \n[INFO] 2022-10-03 10:09:07,120 &lt;module&gt;: MainProcess Calculation took 141,027,339 iterations and 0:44:06.398345.\n</code></pre>\n<p><strong>math_pi.pi(b = 1000000)</strong>\nis faster to a million.  About 40 times faster.  But it cannot go to a Billion.  1 Million is the most digits.</p>\n<p>The GMPY Builtin looks like:</p>\n<pre><code>python pi-pourri.py -v -d 1,000,000,000 -a 11\n[INFO] 2022-10-03 14:33:34,729 &lt;module&gt;: MainProcess Computing π to 1,000,000,000 digits.\n[DEBUG] 2022-10-03 14:33:34,729 compute: MainProcess Starting   const_pi() function from the gmpy2 library formula to 1,000,000,000 decimal places\n[DEBUG] 2022-10-03 15:46:46,575 compute: MainProcess    const_pi() function from the gmpy2 library calulation Done! 1 iterations and 4391.85 seconds.\n[INFO] 2022-10-03 15:46:46,575 &lt;module&gt;: MainProcess Last 5 digits of π were 45519 as expected at offset 999,999,995\n[INFO] 2022-10-03 15:46:46,575 &lt;module&gt;: MainProcess Calculated π to 1,000,000,000 digits using a formula of:\n 11     const_pi() function from the gmpy2 library \n[INFO] 2022-10-03 15:46:46,575 &lt;module&gt;: MainProcess Calculation took 1 iterations and 1:13:11.845652.\n</code></pre>\n<p>The MPmath Builtin is almost as fast. About 12% (6 minutes) slower:</p>\n<pre><code>python pi-pourri.py -v -a 12 -d 1,000,000,000  \n[INFO] 2022-10-04 09:10:37,085 &lt;module&gt;: MainProcess Computing π to 1,000,000,000 digits.\n[DEBUG] 2022-10-04 09:10:37,085 compute: MainProcess Starting   mp.pi() function from the mpmath library formula to 1,000,000,000 decimal places\n[DEBUG] 2022-10-04 10:01:25,321 compute: MainProcess    mp.pi() function from the mpmath library calulation Done! 1 iterations and 3048.22 seconds.\n[INFO] 2022-10-04 10:01:25,338 &lt;module&gt;: MainProcess Last 5 digits of π were 45519 as expected at offset 999,999,995\n[INFO] 2022-10-04 10:01:25,340 &lt;module&gt;: MainProcess Calculated π to 1,000,000,000 digits using a formula of:\n 12     mp.pi() function from the mpmath library \n[INFO] 2022-10-04 10:01:25,343 &lt;module&gt;: MainProcess Calculation took 1 iterations and 0:50:48.250337.\n</code></pre>\n'}]
['https://Stackoverflow.com/questions/19', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/13/']