• Found this old C code to calculate Pi

    From Cri-Cri@21:1/5 to All on Sun Jun 16 20:43:32 2024
    It only does 9 digits at a time, so I wrapped it in some Python to get all decimals in one blow. Results are sort of interesting, but it gets
    increasingly slower:

    $ time python make-pie.py 1000
    141592653589793238462643383279502884197...

    real 0m2,378s
    user 0m2,279s
    sys 0m0,097s

    $ time python make-pie.py 2000
    141592653589793238462643383279502884197...

    real 0m16,254s
    user 0m16,009s
    sys 0m0,232s

    I dare not run it with 10,000 decimals, or it'll probably sit there for a
    week.

    I've checked the first 1,000 and it seems to be exactly like online lists
    of decimals.

    You have to imagine the "3." in the beginning of it.

    That Leibnitz formula is also interesting, but it takes forever to yield
    but a handful of decimals.

    The readme in the C file reads:

    * Computation of the n'th decimal digit of pi with very little memory.
    * Written by Fabrice Bellard on February 26, 1997.
    *
    * We use a slightly modified version of the method described by Simon
    * Plouffe in "On the Computation of the n'th decimal digit of various
    * transcendental numbers" (November 1996). We have modified the algorithm
    * to get a running time of O(n^2) instead of O(n^3log(n)^3).
    *
    * This program uses a variation of the formula found by Gosper in 1974 :
    *
    * pi = sum( (25*n-3)/(binomial(3*n,n)*2^(n-1)), n=0..infinity);
    *
    * This program uses mostly integer arithmetic. It may be slow on some
    * hardwares where integer multiplications and divisons must be done by
    * software. We have supposed that 'int' has a size of at least 32 bits.
    * If your compiler supports 'long long' integers of 64 bits, you may use
    * the integer version of 'mul_mod' (see HAS_LONG_LONG).

    Using LONG LONG I get the following:

    1,000 decimals:

    real 0m1,943s
    user 0m1,835s
    sys 0m0,107s

    2,000 decimals:

    real 0m12,854s
    user 0m12,639s
    sys 0m0,202s

    It's about 250 lines of C.

    https://bellard.org/pi/ (depending on security settings you may have to
    reload the page as http instead of https, SSL certificate warning)

    Are there any quicker things out there, that a normal, non C programmer
    can use? I suppose some type of Cuda thing would be way faster, but I
    don't have that.

    --
    Cri-Cri

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Cri-Cri@21:1/5 to Cri-Cri on Tue Jun 18 19:51:53 2024
    On Sun, 16 Jun 2024 20:43:32 GMT, Cri-Cri wrote:

    It's about 250 lines of C.

    I found a smaller and faster algorithm, but it only creates 800 decimals,
    under 0.015 seconds:
    https://crypto.stanford.edu/pbc/notes/pi/code.html

    --
    Cri-Cri

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Cri-Cri@21:1/5 to Stefan Claas on Tue Jun 18 20:53:09 2024
    On Tue, 18 Jun 2024 22:40:54 +0200, Stefan Claas wrote:

    You should check GitHub, for lot's of pi programs.

    Good idea. Thanks. :)

    --
    Cri-Cri

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Stefan Claas@21:1/5 to Cri-Cri on Tue Jun 18 22:40:54 2024
    Cri-Cri wrote:

    On Sun, 16 Jun 2024 20:43:32 GMT, Cri-Cri wrote:

    It's about 250 lines of C.

    I found a smaller and faster algorithm, but it only creates 800 decimals, under 0.015 seconds:
    https://crypto.stanford.edu/pbc/notes/pi/code.html


    You should check GitHub, for lot's of pi programs.

    Simply enter there 'compute pi', or something similar
    and it should show you many repositories, in various
    programming languages.

    --
    Regards
    Stefan

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)