Just finished calculating pi to 30 trillion places.
#23
here's a translation and mod of this c spigot program https://cs.fit.edu/~mmahoney/cse3101/pi.c.txt all credit goes to that author
the program compiled with -O2 runs in about half a second
you could use this in your string-math by changing the printpi sub to simply convert to string
Code: (Select All)
Const maxdigits = 10000
Dim n As Long: n = ((maxdigits + 3) / 12) + 3
Dim As _Unsigned _Integer64 pi(n)
Dim As Long i, j
Dim As _Unsigned _Integer64 t, m, dq, dm
Dim As Double tm

tm = Timer
pi(1) = 4
i = CLng((3.321928094887362 * 12) * n)
While i > 0
    t = 0
    j = n - 1
    While j >= 0
        t = t + pi(j) * i
        pi(j) = t Mod 1000000000000~&&
        t = t \ 1000000000000~&&
        j = j - 1
    Wend
    dq = 0
    dm = 0
    j = 0
    While j < n
        m = pi(j) + (dm * 1000000000000~&&)
        dq = m \ ((i + i) + 1)
        dm = m Mod ((i + i) + 1)
        pi(j) = dq
        j = j + 1
    Wend
    pi(1) = pi(1) + 2
    i = i - 1
Wend
tm = Timer - tm
printpi pi(), n
Print tm

Sub printpi (pi() As _Unsigned _Integer64, n As Long)
    Dim As Long i, l
    Dim As String s

    Print pi(1); ".";
    i = 2
    While i < (n - 1)
        s = _Trim$(Str$(pi(i)))
        l = Len(s)
        s = String$(12 - l, "0") + s
        Print s;
        i = i + 1
    Wend
    Print
End Sub
Reply


Messages In This Thread
RE: Just finished calculating pi to 30 trillion places. - by Jack - 08-19-2022, 11:38 AM



Users browsing this thread: 10 Guest(s)