Pi: Difference between revisions
m
→Quicker, unverified algo: exchanged some multiplies for additions, increasing performance slightly
(→{{header|Haskell}}: added quicker unverified algo, added link to tio.run) |
m (→Quicker, unverified algo: exchanged some multiplies for additions, increasing performance slightly) |
||
Line 5,474:
There seems to be another algorithm in the original reference article (see the [http://www.rosettacode.org/wiki/Pi#Ada Ada] entry), which produces output a bit faster. However, the math behind the algorithm has not been completely proven. It's faster because it doesn't calculate whether each digit is accumulated properly before squirting it out. When using (slow) arbitrary precision libraries, this avoids a lot of computation time.
<lang vbnet>Imports System, System.Numerics, System.Text
Module
Sub RunPiF(ByVal msg As String)
If msg.Length > 0 Then Console.WriteLine(msg)
Dim first As Boolean = True, stp As
lim As
q, r, t, g, j, h, k, a, b As BigInteger
While True▼
While rc < 1000
▲ j = i << 1 : k = j + i : u = 3 * (k + 1) * (k + 2)
y = CByte(((q * (9 * k - 12) + 5 * r) / (5 * t)))▼
End While
If first Then res.Insert(1, "."c) : first = False
Line 5,502 ⟶ 5,503:
Console.WriteLine(vbLf & "Produced {0} digits in {1:n4} seconds.", rc, et.TotalSeconds)
End Sub
Sub Main(args As String())
RunPiF("Press a key to exit...")
|