Re: Totally OT: Colliding blocks that compute pi

Liste des GroupesRevenir à se design 
Sujet : Re: Totally OT: Colliding blocks that compute pi
De : ldo (at) *nospam* nz.invalid (Lawrence D'Oliveiro)
Groupes : comp.misc sci.electronics.design
Date : 21. Mar 2025, 07:16:44
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vrj08c$ugqc$2@dont-email.me>
References : 1 2 3 4
User-Agent : Pan/0.162 (Pokrosvk)
On Thu, 20 Mar 2025 13:15:38 +0000, SH wrote:

How I wish I could calculate pi

Your computer can do it!

    import decimal

    Dec = decimal.Decimal
    decctx = decimal.getcontext()
    decctx.prec = 64

    def decimal_pi():
        with decimal.localcontext() as decctx :
            decctx.prec += 2    # extra digits for intermediate steps
            t = Dec(3)      # substitute 3.0 for regular floats
            lasts, s, n, na, d, da = 0, 3, 1, 0, 0, 24
            nr_steps = 0
            while s != lasts :
                nr_steps += 1
                lasts = s
                n, na = n + na, na + 8
                d, da = d + da, da + 32
                t = t * n / d
                s += t
            #end while
        #end with
        print("nr_steps = %d" % nr_steps)
        return +s               # unary plus applies the new precision
    #end decimal_pi

    print(decimal_pi())

output:

    nr_steps = 104
    3.141592653589793238462643383279502884197169399375105820974944592

Taken from a presentation I did here
<https://github.com/HamPUG/meetings/blob/master/2022/2022-11-14/ldo/Continued%20Fractions.ipynb>.

I tried continued fractions, but found them a waste of time.

Date Sujet#  Auteur
18 Mar 25 * Totally OT: Colliding blocks that compute pi29Sylvia Else
18 Mar 25 +* Re: Totally OT: Colliding blocks that compute pi2yeti
18 Mar 25 i`- Re: Totally OT: Colliding blocks that compute pi1yeti
18 Mar 25 +* Re: Totally OT: Colliding blocks that compute pi2Don Y
18 Mar 25 i`- Re: Totally OT: Colliding blocks that compute pi1Don Y
18 Mar 25 +- Re: Totally OT: Colliding blocks that compute pi1Lawrence D'Oliveiro
18 Mar 25 +* Re: Totally OT: Colliding blocks that compute pi5yeti
20 Mar 25 i+* Re: Totally OT: Colliding blocks that compute pi3brian
20 Mar 25 ii`* Re: Totally OT: Colliding blocks that compute pi2SH
21 Mar 25 ii `- Re: Totally OT: Colliding blocks that compute pi1Lawrence D'Oliveiro
20 Mar 25 i`- Re: Totally OT: Colliding blocks that compute pi1Sn!pe
18 Mar 25 +* Re: Totally OT: Colliding blocks that compute pi15john larkin
18 Mar 25 i+* Re: Totally OT: Colliding blocks that compute pi7john larkin
19 Mar 25 ii+* Re: Totally OT: Colliding blocks that compute pi3Sn!pe
20 Mar 25 iii`* Re: Totally OT: Colliding blocks that compute pi2brian
21 Mar 25 iii `- Re: Totally OT: Colliding blocks that compute pi1Lawrence D'Oliveiro
23 Mar 25 ii`* Re: Totally OT: Colliding blocks that compute pi3Tom Del Rosso
23 Mar 25 ii +- Re: Totally OT: Colliding blocks that compute pi1john larkin
24 Mar 25 ii `- Re: Totally OT: Colliding blocks that compute pi1Lawrence D'Oliveiro
23 Mar 25 i`* Re: Totally OT: Colliding blocks that compute pi7candycanearter07
23 Mar 25 i +* Re: Totally OT: Colliding blocks that compute pi4piglet
24 Mar 25 i i`* Re: Totally OT: Colliding blocks that compute pi3candycanearter07
24 Mar 25 i i `* Re: Totally OT: Colliding blocks that compute pi2yeti
25 Mar 25 i i  `- Re: Totally OT: Colliding blocks that compute pi1candycanearter07
24 Mar 25 i `* Re: Totally OT: Colliding blocks that compute pi2Scott Dorsey
24 Mar 25 i  `- Test 11Joe Gwinn
4 May 25 `* Re: Totally OT: Colliding blocks that compute pi3Tom Del Rosso
4 May 25  `* Re: Totally OT: Colliding blocks that compute pi2Sylvia Else
4 May 25   `- Re: Totally OT: Colliding blocks that compute pi1Tom Del Rosso

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal