Pi: Difference between revisions

15,301 bytes added ,  3 months ago
m
m (→‎{{header|Erlang}}: updated syntaxhighlight lang=, etc...)
m (→‎{{header|Wren}}: Minor tidy)
(15 intermediate revisions by 9 users not shown)
Line 18:
{{trans|D}}
 
<syntaxhighlight lang="11l">V ndigits = 0
V q = BigInt(1)
V r = BigInt(0)
Line 72:
{{trans|FORTRAN}}
The program uses one ASSIST macro (XPRNT) to keep the code as short as possible.
<langsyntaxhighlight lang="360asm">* Spigot algorithm do the digits of PI 02/07/2016
PISPIG CSECT
USING PISPIG,R13 base register
Line 175:
NBUF EQU 201 number of 5 decimals
NVECT EQU 3350 nvect=ceil(nbuf*50/3)
END PISPIG</langsyntaxhighlight>
{{out}}
<pre>
Line 206:
uses same algorithm as Go solution, from http://web.comlab.ox.ac.uk/people/jeremy.gibbons/publications/spigot.pdf
;pi_digits.adb:
<langsyntaxhighlight Adalang="ada">with Ada.Command_Line;
with Ada.Text_IO;
with GNU_Multiple_Precision.Big_Integers;
Line 317:
end if;
Print_Pi (N);
end Pi_Digits;</langsyntaxhighlight>
output:
<pre> 3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 2 7 9 5 0 2 8 8 4 1 9 7 1 6 9 3 9 9 3 7 5 1 0 5 8 2 0 9 7 4 9 4 4 5 9 2 3 0 7 8 1 6 4 0 6 2 8 6 2 0 8 9 9 8 6 2 8 0 3 4 8 2 5 3 4 2 1 1 7 0 6 7</pre>
Line 327:
{{wont work with|ELLA ALGOL 68|Any (with appropriate job cards) - tested with release [http://sourceforge.net/projects/algol68/files/algol68toc/algol68toc-1.8.8d/algol68toc-1.8-8d.fc9.i386.rpm/download 1.8-8d] - due to extensive use of '''format'''[ted] ''transput''.}}
This codes uses 33 decimals places as a test case. Performance is O(2) based on the number of decimal places required.
<langsyntaxhighlight lang="algol68">#!/usr/local/bin/a68g --script #
 
INT base := 10;
Line 377:
# OD #);
print(new line)
)</langsyntaxhighlight>
Output:
<pre>
Line 385:
=={{header|Arturo}}==
 
<langsyntaxhighlight lang="rebol">q: 1
r: 0
t: 1
Line 421:
r: nr
]
]</langsyntaxhighlight>
 
{{out}}
Line 455:
{{libheader|MPL}}
Could be optimized with Ipp functions, but runs fast enough for me as-is. Does not work in AHKLx64.
<langsyntaxhighlight lang="autohotkey">#NoEnv
#SingleInstance, Force
SetBatchLines, -1
Line 520:
, MP_CPY(r, nr)
}
}</langsyntaxhighlight>
 
=={{header|BASIC}}==
 
==={{header|Applesoft BASIC}}===
<langsyntaxhighlight lang="basic">10 REM ADOPTED FROM COMMODORE BASIC
20 N = 100: REM N MAY BE INCREASED, BUT WILL SLOW EXECUTION
30 LN = INT(10*N/3)+16
Line 577:
550 RETURN
</syntaxhighlight>
</lang>
 
==={{header|Atari 8-bit}}===
<langsyntaxhighlight lang="basic">10 REM ADOPTED FROM COMMODORE BASIC
20 N = 100: REM N MAY BE INCREASED, BUT WILL SLOW EXECUTION
30 LN = INT(10*N/3)+16
Line 631:
530 ND = 0
550 RETURN
</syntaxhighlight>
</lang>
 
 
==={{header|BASIC256}}===
{{Trans|Pascal}} below, and originally published by Stanley Rabinowitz in [http://www.mathpropress.com/stan/bibliography/spigot.pdf].
<syntaxhighlight lang="basic256">cls
<lang BASIC256>cls
 
n =1000
Line 694:
print d;
end if
return</langsyntaxhighlight>
 
Output:
Line 700:
3.14159265358979323846264338327950288419716939937510582097494459230781...
</pre>
 
==={{header|Chipmunk Basic}}===
{{works with|Chipmunk Basic|3.6.4}}
{{works with|Applesoft BASIC}}
{{works with|MSX_BASIC}}
{{works with|QBasic}}
{{trans|Applesoft BASIC}}
<syntaxhighlight lang="qbasic">100 REM adopted from Applesoft BASIC
110 n = 100 : rem n may be increased, but will slow execution
120 ln = int(10*n/3)+16
130 nd = 1
140 dim a(ln)
150 n9 = 0
160 pd = 0 : rem First pre-digit is a 0
170 rem
180 for j = 1 to ln
190 a(j-1) = 2 : rem Start wirh 2S
200 next j
210 rem
220 for j = 1 to n
230 q = 0
240 for i = ln to 1 step -1 : rem Work backwards
250 x = 10*a(i-1)+q*i
260 a(i-1) = x-(2*i-1)*int(x/(2*i-1)) : rem X - Int ( X / Y) * Y
270 q = int(x/(2*i-1))
280 next i
290 a(0) = q-10*int(q/10)
300 q = int(q/10)
310 if q = 9 then n9 = n9+1 : goto 510
320 if q <> 10 then goto 440
330 rem Q == 10
340 d = pd+1 : gosub 560
350 if n9 <= 0 then goto 400
360 for k = 1 to n9
370 d = 0 : gosub 560
380 next k
390 rem End If
400 pd = 0
410 n9 = 0
420 goto 510
430 rem Q <> 10
440 d = pd : gosub 560
450 pd = q
460 if n9 = 0 then goto 510
470 for k = 1 to n9
480 d = 9 : gosub 560
490 next k
500 n9 = 0
510 next j
520 print str$(pd)
530 end
540 rem
550 rem Output digits
560 if nd = 0 then print str$(d); : return
570 if d = 0 then return
580 print str$(d);".";
590 nd = 0
600 return</syntaxhighlight>
 
==={{header|Commodore BASIC}}===
This works with Commodore Basic V2
 
<langsyntaxhighlight lang="basic">10 PRINT CHR$(147)
20 N = 100: REM N MAY BE INCREASED, BUT WILL SLOW EXECUTION
30 LN = INT(10*N/3)+16
Line 746 ⟶ 804:
410 N9 = 0
450 NEXT J
460 PRINT RIGHT$(STR$(PD),1)
470 END
480 REM
490 REM OUTPUT DIGITS
500 IF ND=0 THEN PRINT RIGHT$(STR$(D),1);: RETURN
510 IF D=0 THEN RETURN
520 PRINT RIGHT$(STR$(D),1);".";
530 ND = 0
550 RETURN
</syntaxhighlight>
</lang>
 
==={{header|GW-BASIC}}===
{{works with|PC-BASIC|any}}
The [[#Chipmunk_Basic|Chipmunk Basic]] solution works without any changes.
 
==={{header|Integer Basic}}===
 
Integer version was derived from the Pascal_spigot without any optimisation. It is more than 33% faster than the Applesoft version since it runs natively with integers.
 
<langsyntaxhighlight lang="basic"> 10 REM PI CALCULATION WITH SPIGOT
100 N=100: REM MAX N=260 TO AVOID OVERFLOW
110 LEN=(10*N)/3
Line 806 ⟶ 867:
1080 IF I>0 THEN GOTO 1040
1090 RETURN
</syntaxhighlight>
</lang>
 
==={{header|Osborne 1 MBASICIS-BASIC}}===
<syntaxhighlight lang="is-basic">100 PROGRAM "PI.bas"
110 LET N=100 ! Nuber of digits
120 LET LN=INT(10*N/3)+16
130 DIM A(LN)
140 LET PD,N9=0:LET ND=1
150 FOR J=1 TO LN
160 LET A(J-1)=2
170 NEXT
180 FOR J=1 TO N
190 LET Q=0
200 FOR I=LN TO 1 STEP-1
210 LET X=10*A(I-1)+Q*I
220 LET A(I-1)=X-(2*I-1)*INT(X/(2*I-1))
230 LET Q=INT(X/(2*I-1))
240 NEXT
250 LET A(0)=Q-10*INT(Q/10)
260 LET Q=INT(Q/10)
270 SELECT CASE Q
280 CASE 9
290 LET N9=N9+1
300 CASE 10
310 LET D=PD+1:CALL WRITE
320 IF N9>0 THEN
330 FOR K=1 TO N9
340 LET D=0:CALL WRITE
350 NEXT
360 END IF
370 LET PD,N9=0
380 CASE ELSE
390 LET D=PD:CALL WRITE
400 LET PD=Q
410 IF N9<>0 THEN
420 FOR K=1 TO N9
430 LET D=9:CALL WRITE
440 NEXT
450 LET N9=0
460 END IF
470 END SELECT
480 NEXT
490 PRINT STR$(PD)(1)
500 END
510 DEF WRITE
520 IF ND=0 THEN
530 PRINT STR$(D)(1);
540 ELSE IF D<>0 THEN
550 PRINT STR$(D)(1);".";
560 LET ND=0
570 END IF
580 END DEF</syntaxhighlight>
 
==={{header|MSX Basic}}===
The [[#Chipmunk_Basic|Chipmunk Basic]] solution works without any changes.
 
==={{header|Osborne 1 MBASIC}}===
Osborne 1 program is slightly different to allow it to keep the numbers all on the main screen rather than scrolling off to the right...
 
<langsyntaxhighlight lang="basic">10 REM ADOPTED FROM COMMODORE BASIC
15 CR=0
20 N = 100: REM N MAY BE INCREASED, BUT WILL SLOW EXECUTION
Line 865 ⟶ 979:
530 ND = 0
550 RETURN
</syntaxhighlight>
</lang>
 
==={{header|TRS-80 Model 4 BASIC}}===
 
<langsyntaxhighlight lang="basic"> 10 REM ADOPTED FROM COMMODORE BASIC
20 N = 100: REM N MAY BE INCREASED, BUT WILL SLOW EXECUTION
30 LN = INT(10*N/3)+16
Line 920 ⟶ 1,034:
530 ND = 0
550 RETURN
</syntaxhighlight>
</lang>
 
=={{header|BBC BASIC}}==
===BASIC version===
<langsyntaxhighlight lang="bbcbasic"> WIDTH 80
M% = (HIMEM-END-1000) / 4
DIM B%(M%)
Line 946 ⟶ 1,060:
E% = D% MOD 100 : L% = 2
ENDCASE
NEXT</langsyntaxhighlight>
 
===Assembler version===
{{works with|BBC BASIC for Windows}}
The first 250,000 digits output have been verified.
<langsyntaxhighlight lang="bbcbasic"> DIM P% 32
[OPT 2 :.pidig mov ebp,eax :.pi1 imul edx,ecx : mov eax,[ebx+ecx*4]
imul eax,100 : add eax,edx : cdq : div ebp : mov [ebx+ecx*4],edx
Line 973 ⟶ 1,087:
E% = D% MOD 100 : L% = 2
ENDCASE
NEXT</langsyntaxhighlight>
'''Output:'''
<pre>
Line 996 ⟶ 1,110:
{{works with|GNU bc}}
{{works with|OpenBSD bc}}
<langsyntaxhighlight lang="bc">#!/usr/bin/bc -l
 
scaleinc= 20
Line 1,025 ⟶ 1,139:
scale= wantscale
oldpi= pi / 1
}</langsyntaxhighlight>
Output:
<pre>
Line 1,054 ⟶ 1,168:
=={{header|Bracmat}}==
{{trans|Icon_and_Unicon}}
<langsyntaxhighlight lang="bracmat"> ( pi
= f,q r t k n l,first
. !arg:((=?f),?q,?r,?t,?k,?n,?l)
Line 1,082 ⟶ 1,196:
)
)
& pi$((=.put$!arg),1,0,1,1,3,3)</langsyntaxhighlight>
Output:
<pre>3.1415926535897932384626433832795028841971693993751058209749445923078164062
Line 1,151 ⟶ 1,265:
 
Using Machin's formula. The "continuous printing" part is silly: the algorithm really calls for a preset number of digits, so the program repeatedly calculates Pi digits with increasing length and chop off leading digits already displayed. But it's still faster than the unbounded Spigot method by an order of magnitude, at least for the first 100k digits.
<langsyntaxhighlight Clang="c">#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
Line 1,218 ⟶ 1,332:
 
return 0;
}</langsyntaxhighlight>
 
=={{header|C sharp|C#}}==
Line 1,224 ⟶ 1,338:
{{trans|Java}}
 
<syntaxhighlight lang="csharp">using System;
using System.Numerics;
 
Line 1,277 ⟶ 1,391:
Adopted Version:
{{libheader|System.Numerics}}
<syntaxhighlight lang="csharp">using System;
using System.Collections.Generic;
using System.Linq;
Line 1,366 ⟶ 1,480:
 
=={{header|C++}}==
<langsyntaxhighlight lang="cpp">#include <iostream>
#include <boost/multiprecision/cpp_int.hpp>
 
Line 1,421 ⟶ 1,535:
std::cout << *++g; // increment to the next digit and print
}
}</langsyntaxhighlight>
{{out}}
<pre>
Line 1,429 ⟶ 1,543:
=={{header|Clojure}}==
{{Trans|Python}}
<langsyntaxhighlight lang="lisp">(ns pidigits
(:gen-class))
 
Line 1,467 ⟶ 1,581:
(println))
(print q))
</syntaxhighlight>
</lang>
{{Output}}
<pre>
Line 1,478 ⟶ 1,592:
 
=={{header|Common Lisp}}==
<langsyntaxhighlight lang="lisp">(defun pi-spigot ()
(labels
((g (q r t1 k n l)
Line 1,502 ⟶ 1,616:
(* t1 l)))
(+ l 2))))))
(g 1 0 1 1 3 3)))</langsyntaxhighlight>
{{out}}
<pre>CL-USER> (pi-spigot)
Line 1,509 ⟶ 1,623:
=={{header|Crystal}}==
{{trans|Ruby}}
<langsyntaxhighlight lang="ruby">require "big"
 
def pi
Line 1,539 ⟶ 1,653:
 
pi { |digit_or_dot| print digit_or_dot; STDOUT.flush }
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 1,546 ⟶ 1,660:
=={{header|D}}==
This modified [[wp:Spigot_algorithm|Spigot algorithm]] does not continue infinitely, because its required memory grow as the number of digits need to print.
<syntaxhighlight lang="d">import std.stdio, std.conv, std.string;
 
struct PiDigits {
Line 1,597 ⟶ 1,711:
534211706</pre>
===Alternative version===
<syntaxhighlight lang="d">import std.stdio, std.bigint;
 
void main() {
Line 1,656 ⟶ 1,770:
 
introcs dot cs dot princeton dot edu slash java slash data slash pi-10million.txt
<langsyntaxhighlight lang="delphi">
unit Pi_BBC_Main;
 
Line 1,794 ⟶ 1,908:
 
end.
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 1,810 ⟶ 1,924:
With only a few changes (noted in the comments), the same code can be used to
output the first 2070 digits of e.
<langsyntaxhighlight lang="edsac">
[EDSAC program, Initial Orders 2.
Calculates digits of pi by spigot algorithm.
Line 2,030 ⟶ 2,144:
E 11 Z [define entry point]
P F [acc = 0 on entry]
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 2,041 ⟶ 2,155:
=={{header|Elixir}}==
{{trans|Erlang}}
<langsyntaxhighlight lang="elixir">defmodule Pi do
def calc, do: calc(1,0,1,1,3,3,0)
Line 2,057 ⟶ 2,171:
end
 
Pi.calc</langsyntaxhighlight>
 
{{out}}
Line 2,080 ⟶ 2,194:
 
=={{header|Erlang}}==
<syntaxhighlight lang="erlang">% Implemented by Arjun Sunel
-module(pi_calculation).
-export([main/0]).
Line 2,141 ⟶ 2,255:
===Translation of Haskell===
{{trans|Haskell}}
<syntaxhighlight lang="fsharp">let rec g q r t k n l = seq {
if 4I*q+r-t < n*t
then
Line 2,160 ⟶ 2,274:
===As an Unfold===
Haskell can probably do this as an unfold, it has not so I shall in F#
<syntaxhighlight lang="fsharp">
// Generate Pi as above using unfold. Nigel Galloway: March 15th., 2022
let π()=Seq.unfold(fun(q,r,t,k,n,l)->Some(if 4I*q+r-t < n*t then(Some(int n),((10I*q),(10I*(r-n*t)),t,k,((10I*(3I*q+r))/t-10I*n),l)) else (None,((q*k),((2I*q+r)*l),(t*l),(k+1I),((q*(7I*k+2I)+r*l)/(t*l)),(l+2I)))))(1I,0I,1I,1I,3I,3I)|>Seq.choose id
Line 2,168 ⟶ 2,282:
=={{header|Factor}}==
{{trans|Oforth}}
<langsyntaxhighlight lang="factor">USING: combinators.extras io kernel locals math prettyprint ;
IN: rosetta-code.pi
 
Line 2,188 ⟶ 2,302:
] forever ;
 
MAIN: calc-pi-digits</langsyntaxhighlight>
 
=={{header|Fortran}}==
This is a modernized version of the example Fortran programme written by S. Rabinowitz in 1991. It works in base 100000 and the key step is the initialisation of all elements of VECT to 2. The format code of I5.5 means I5 output but with all leading spaces made zero so that 66 comes out as "00066", not " 66".
 
<syntaxhighlight lang="fortran">
<lang Fortran>
program pi
implicit none
Line 2,214 ⟶ 2,328:
write (*,'(i2,"."/(1x,10i5.5))') buffer
end program pi
</syntaxhighlight>
</lang>
The output is accumulated in BUFFER then written in one go at the end, but it could be written as successive values as each is calculated without much extra nitpickery: instead of <code>BUFFER(N) = MORE + K</code> for example just <code>WRITE (*,"(I5.5)") MORE + K</code> and no need for array BUFFER.
<pre>
Line 2,242 ⟶ 2,356:
This is an alternate version using an unbounded spigot. Higher precision is accomplished by using the Fortran Multiple Precision
Library, FMLIB (http://myweb.lmu.edu/dmsmith/fmlib.html), provided by Dr. David M. Smith (dsmith@lmu.edu), Mathematics Professor (Emeritus) at Loyola Marymount University. We use the default precision which is about 50 significant digits.
<syntaxhighlight lang="fortran">
<lang Fortran>
!================================================
program pi_spigot_unbounded
Line 2,291 ⟶ 2,405:
 
end program
</syntaxhighlight>
</lang>
 
=={{header|FreeBASIC}}==
{{libheader|GMP}}
<langsyntaxhighlight lang="freebasic">' version 05-07-2018
' compile with: fbc -s console
 
Line 2,348 ⟶ 2,462:
mpz_set(r, tmp2)
End If
Loop</langsyntaxhighlight>
{{out}}
<pre>3.
Line 2,366 ⟶ 2,480:
The code for <code>compute_pi()</code> is from [http://www.cs.ox.ac.uk/people/jeremy.gibbons/publications/spigot.pdf]. The number of digits may be given on the command line as an argument. If there's no argument, the program will run until interrupted.
 
<langsyntaxhighlight lang="funl">def compute_pi =
def g( q, r, t, k, n, l ) =
if 4*q + r - t < n*t
Line 2,385 ⟶ 2,499:
print( d )
 
println()</langsyntaxhighlight>
 
=={{header|FutureBasic}}==
This old-school code still works on Mac OS Monterey and is expected to work on Ventura, but it needs a modern refactoring.
<langsyntaxhighlight lang="futurebasic">
 
_maxlong = 0x7fffffff
Line 2,559 ⟶ 2,673:
 
HandleEvents
</syntaxhighlight>
</lang>
 
Output:
Line 2,641 ⟶ 2,755:
Code below is a simplistic translation of Haskell code in [http://web.comlab.ox.ac.uk/oucl/work/jeremy.gibbons/publications/spigot.pdf Unbounded Spigot Algorithms for the Digits of Pi]. This is the algorithm specified for the [http://shootout.alioth.debian.org/u64q/performance.php?test=pidigits pidigits] benchmark of the [http://shootout.alioth.debian.org/ Computer Language Benchmarks Game].
(The standard Go distribution includes [http://golang.org/test/bench/shootout/pidigits.go source] submitted to the benchmark site, and that code runs stunning faster than the code below.)
<langsyntaxhighlight lang="go">package main
 
import (
Line 2,723 ⟶ 2,837:
}
}
}</langsyntaxhighlight>
 
=={{header|Groovy}}==
{{trans|Java}}
Solution:
<langsyntaxhighlight lang="groovy">BigInteger q = 1, r = 0, t = 1, k = 1, n = 3, l = 3
String nn
boolean first = true
Line 2,737 ⟶ 2,851:
: ['' , first, q*k , (2*q + r)*l , t*l, k + 1, (q*(7*k + 2) + r*l)/(t*l), l + 2]
print nn
}</langsyntaxhighlight>
 
Output (thru first 1000 iterations):
Line 2,744 ⟶ 2,858:
=={{header|Haskell}}==
The code from [http://www.cs.ox.ac.uk/people/jeremy.gibbons/publications/spigot.pdf]:
<langsyntaxhighlight lang="haskell">pi_ = g (1, 0, 1, 1, 3, 3)
where
g (q, r, t, k, n, l) =
Line 2,762 ⟶ 2,876:
, k + 1
, div (q * (7 * k + 2) + r * l) (t * l)
, l + 2)</langsyntaxhighlight>
 
===Complete command-line program===
Line 2,768 ⟶ 2,882:
{{Works with|GHC|7.4.1}}
 
<langsyntaxhighlight lang="haskell">#!/usr/bin/runhaskell
 
import Control.Monad
Line 2,785 ⟶ 2,899:
main = do
hSetBuffering stdout $ BlockBuffering $ Just 80
forM_ digs putChar</langsyntaxhighlight>
 
{{out}}
Line 2,794 ⟶ 2,908:
===Quicker, Unverified Algorithm ===
Snippet verbatim from source .pdf:
<langsyntaxhighlight Haskelllang="haskell">piG3 = g(1,180,60,2) where
g(q,r,t,i) = let (u,y)=(3*(3*i+1)*(3*i+2),div(q*(27*i-12)+5*r)(5*t))
in y : g(10*q*i*(2*i-1),10*u*(q*(5*i-2)+r-y*t),t*u,i+1)</langsyntaxhighlight>
This is more efficient because each term converges in less than one step, so no checking needs to be done partway through the iteration. Only caveat is that the convergence is ''on average'' slightly over one digit, so there is a chance that, if one checked enough digits, one may find a gap where a digit would be incorrect. Though it seems to be OK for the first 100k digits, or so.
 
Line 2,803 ⟶ 2,917:
=={{header|Icon}} and {{header|Unicon}}==
{{Trans|PicoLisp}} based on Jeremy Gibbons' Haskell solution.
<langsyntaxhighlight lang="icon">procedure pi (q, r, t, k, n, l)
first := "yes"
repeat { # infinite loop
Line 2,830 ⟶ 2,944:
procedure main ()
every (writes (pi (1,0,1,1,3,3)))
end</langsyntaxhighlight>
 
=={{header|J}}==
<langsyntaxhighlight lang="j">pi=: 3 :0
echo"0 '3.1'
i=. 0
Line 2,839 ⟶ 2,953:
echo -/ 1 10 * <.@o. 10x ^ 1 0 + i
end.
)</langsyntaxhighlight>
Example use:
<langsyntaxhighlight lang="j"> pi''
3
.
Line 2,853 ⟶ 2,967:
5
3
...</langsyntaxhighlight>
 
=={{header|Java}}==
{{trans|Icon}}
<langsyntaxhighlight lang="java">import java.math.BigInteger ;
 
public class Pi {
Line 2,901 ⟶ 3,015:
p.calcPiDigits() ;
}
}</langsyntaxhighlight>
 
Output :
Line 2,914 ⟶ 3,028:
process.stdout.write will work in Node.js; to make this work in a browser, change it to document.body.textContent += .
 
<syntaxhighlight lang="text">let q = 1n, r = 180n, t = 60n, i = 2n;
for (;;) {
let y = (q*(27n*i-12n)+5n*r)/(5n*t);
Line 2,924 ⟶ 3,038:
process.stdout.write(y.toString());
if (i === 3n) { process.stdout.write('.'); }
}</langsyntaxhighlight>
 
=== Web Page version ===
Line 2,930 ⟶ 3,044:
This shows how to load the previous code into a webpage that writes digits out without freezing the browser
 
<langsyntaxhighlight lang="html"><html><head><script src='https://rawgit.com/andyperlitch/jsbn/v1.1.0/index.js'></script></head>
<body style="width: 100%"><tt id="pi"></tt><tt>...</tt>
<script async defer>
Line 2,973 ⟶ 3,087:
calcPi();
</script>
</body></html></langsyntaxhighlight>
 
=== Web Page using BigInt ===
Line 2,979 ⟶ 3,093:
Above converted to use BigInt
 
<langsyntaxhighlight lang="html"><html>
<head>
</head>
Line 3,026 ⟶ 3,140:
</script>
</body>
</html></langsyntaxhighlight>
Note: removing the parameters to continueCalcPi() as shown may eat (even) more memory, not entirely sure about that.
 
Line 3,032 ⟶ 3,146:
Returns an approximation of Pi.
 
<syntaxhighlight lang="text">var calcPi = function() {
var n = 20000;
var pi = 0;
Line 3,045 ⟶ 3,159:
}
return pi;
}</langsyntaxhighlight>
 
=={{header|jq}}==
Line 3,069 ⟶ 3,183:
spigot grow very slightly more than linearly.
 
<langsyntaxhighlight lang="jq"># The Gibbons spigot, in the mold of the [[#Groovy]] and [[#Python]] programs shown on this page.
# The "bigint" functions needed are:
# long_minus long_add long_multiply long_div
Line 3,127 ⟶ 3,241:
;
 
pi_spigot</langsyntaxhighlight>
{{out}}
<div style="overflow:scroll; height:200px;">
<langsyntaxhighlight lang="sh">$ jq -M -n -c -f pi.bigint.jq
[0,9,"3"]
[1,14,"1"]
Line 3,435 ⟶ 3,549:
[302,8623,"2"]
...
</langsyntaxhighlight></div>
 
=={{header|Julia}}==
Julia comes with built-in support for computing π in arbitrary precision (using the GNU MPFR library). This implementation computes π at precisions that are repeatedly doubled as more digits are needed, printing one digit at a time and never terminating (until it runs out of memory) as specified:
<langsyntaxhighlight lang="julia">let prec = precision(BigFloat), spi = "", digit = 1
while true
if digit > lastindex(spi)
Line 3,449 ⟶ 3,563:
digit += 1
end
end</langsyntaxhighlight>
 
Output:
Line 3,456 ⟶ 3,570:
=={{header|Kotlin}}==
{{trans|Java}}
<langsyntaxhighlight lang="scala">// version 1.1.2
 
import java.math.BigInteger
Line 3,500 ⟶ 3,614:
}
 
fun main(args: Array<String>) = calcPi()</langsyntaxhighlight>
 
{{out}}
Line 3,506 ⟶ 3,620:
3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745...
</pre>
 
=={{header|Lambdatalk}}==
1) We can build a lambdatalk function using the lib_BN javascript library.
 
<syntaxhighlight lang="scheme">
{require lib_BN}
 
{def genpi
{def genpi.loop
{lambda {:n :pi :q :r :t :i :z}
{if {> :z :n}
then :pi
else {let { {:n :n} {:pi :pi} {:q :q} {:r :r} {:t :t} {:i :i} {:z :z}
{:digit {BN./ {BN.+ {BN.* {BN.- {BN.* :i 27} 12} :q}
{BN.* :r 5} }
{BN.* :t 5} } }
{:u {BN.* {BN.+ {BN.* :i 3} 1}
{BN.* 3 {BN.+ {BN.* :i 3} 2} } } }
} {genpi.loop :n
{BN.+ :pi :digit}
{BN.* {BN.* :q 1}
{BN.* :i {BN.- {BN.* :i 2} 1} }}
{BN.* {BN.* :u 1}
{BN.+ {BN.* :q {BN.- {BN.* :i 5} 2} }
{BN.- :r {BN.* :t :digit} }}}
{BN.* :t :u}
{BN.+ :i 1}
{+ :z 1}} }}}}
{lambda {:n}
{genpi.loop :n # 1 180 60 2 0} }}
-> genpi
 
We can generate π with 72 digits in about 500ms.
 
{BN.DEC 72}
-> 72 digits
{genpi 60}
-> 3.141592653589793238462643383279502884197169399375105820974944592307816406
</syntaxhighlight>
 
To go further the best is to build a javascript primitive using the script special form.
 
<syntaxhighlight lang="scheme">
{script
LAMBDATALK.DICT["spigot"] = function() {
function generateDigitsOfPi(max) {
var pi = "";
var z = 0;
var q = 1n;
var r = 180n;
var t = 60n;
var i = 2n;
while (z < max) {
var digit = ((i * 27n - 12n) * q + r * 5n) / (t * 5n);
pi += digit;
var u = (i * 3n + 1n) * 3n * (i * 3n + 2n);
r = u * 10n * (q * (i * 5n - 2n) + (r - t * digit));
q = q * 10n * i * (i * 2n - 1n);
i = i + 1n;
t = t * u;
z++;
}
return pi
}
var args = arguments[0].trim();
return generateDigitsOfPi( args );
};
}
 
We can generate 1000 digits of π in about 70ms
 
3.{W.rest {spigot 100}}
-> 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647093844609550582231725359408128481117450284102701938521105559644622948954930381964428810975665933446128475648233786783165271201909145648566923460348610454326648213393607260249141273724587006606315588174881520920962829254091715364367892590360011330530548820466521384146951941511609433057270365759591953092186117381932611793105118548074462379962749567351885752724891227938183011949129833673362440656643086021394946395224737190702179860943702770539217176293176752384674818467669405132000568127145263560827785771342757789609173637178721468440901224953430146549585371050792279689258923542019956112129021960864034418159813629774771309960518707211349999998372978049951059731732816096318595024459455346908302642522308253344685035261931188171010003137838752886587533208381420617177669147303598253490428755468731159562863882353787593751957781857780532171226806613001927876611195909216420198
 
</syntaxhighlight>
 
=={{header|Lasso}}==
Based off [http://crypto.stanford.edu/pbc/notes/pi/code.html Dik T. Winter's C implementation of Beeler et al. 1972, Item 120].
<langsyntaxhighlight Lassolang="lasso">#!/usr/bin/lasso9
define generatePi => {
Line 3,539 ⟶ 3,728:
loop(200) => {
stdout(#pi_digits())
}</langsyntaxhighlight>
Output (first 100 places):
<pre>3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067
Line 3,546 ⟶ 3,735:
=={{header|Liberty BASIC}}==
Pretty slow if you run for over 100 digits...
<langsyntaxhighlight lang="lb"> ndigits = 0
 
q = 1
Line 3,580 ⟶ 3,769:
wend
 
end</langsyntaxhighlight>
<pre>
3.141592653589793238462643383279502884197
Line 3,589 ⟶ 3,778:
=={{header|Lua}}==
{{trans|Pascal}}
<langsyntaxhighlight lang="lua">a = {}
n = 1000
len = math.modf( 10 * n / 3 )
Line 3,629 ⟶ 3,818:
end
end
print( predigit )</langsyntaxhighlight>
<pre>03141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086 ...</pre>
 
Line 3,639 ⟶ 3,828:
 
 
<syntaxhighlight lang="m2000 interpreter">
<lang M2000 Interpreter>
Module Checkpi {
Module FindPi(Digits){
Line 3,735 ⟶ 3,924:
Modules ? ' current module exist
Stack ' Stack of values ' has to be empty, we didn't use current stack for values.
</syntaxhighlight>
</lang>
 
=={{header|Mathematica}} / {{header|Wolfram Language}}==
User can interrupt computation using "Alt+." or "Cmd+." on a Mac.
<langsyntaxhighlight Mathematicalang="mathematica">WriteString[$Output, "3."];
For[i = -1, True, i--,
WriteString[$Output, RealDigits[Pi, 10, 1, i][[1, 1]]]; Pause[.05]];</langsyntaxhighlight>
 
=={{header|MATLAB}} / {{header|Octave}}==
Requires the Variable Precision Integer (vpi) Toolbox
Matlab and Octave use double precision numbers per default, and pi is a builtin constant value. Arbitrary precision is only implemented in some additional toolboxes (e.g. symbolic toolbox).
<syntaxhighlight lang="matlab">
<lang MATLAB>pi</lang>
function pi_str = piSpigot(N)
% Return N digits of pi using Gibbons's first spigot algorithm.
% If N is omitted, the digits are printed ad infinitum.
% Uses the expansion
% pi = sum_{i=0} (i!)^2 2^{i+1} /(2i+1)!
% = 2 + 1/3 * ( 2 + 2/5 * (2 + 3/7 * ( 2 + 4/9 * ( ..... )))))
% = (2 + 1/3 *)(2 + 2/5 *)(2 + 3/7 *)...
% where the terms in the last expression represent Linear Fractional
% Transforms (LFTs).
%
% Requires the Variable Precision Integer (vpi) Toolbox
%
% Reference:
% "Unbounded Spigot Algorithms for the Digits of Pi" by J. Gibbons, 2004
% American Mathematical Monthly, vol. 113.
if nargin < 1
N = Inf;
lineLength = 50;
else
pi_str = repmat(' ',1,N);
end
 
q = vpi(1);
r = vpi(0);
t = vpi(1);
k = 1; % If printing more than 3E15 digits, use k = vpi(1);
 
i = 1;
first_digit = true;
while i <= N
threeQplusR = 3*q + r;
n = double(threeQplusR / t);
if q+threeQplusR < (n+1)*t
d = num2str(n);
if isinf(N)
fprintf(1,'%s', d);
if first_digit
fprintf(1,'.');
first_digit = false;
i = i+1;
end
if i == lineLength
fprintf(1,'\n');
i = 0;
end
else
pi_str(i) = d;
end
q = 10*q;
r = 10*(r-n*t);
i = i + 1;
else
t = (2*k+1)*t;
r = (4*k+2)*q + (2*k+1)*r;
q = k*q;
k = k + 1;
end
end
end
</syntaxhighlight>
<pre>
>> pipiSpigot
3.141592653589793238462643383279502884197169399375
ans = 3.1416
10582097494459230781640628620899862803482534211706
> printf('%.60f\n',pi)
79821480865132823066470938446095505822317253594081
3.141592653589793115997963468544185161590576171875000000000000>> format long
28481117450284102701938521105559644622948954930381
96442881097566593344612847564823378678316527120190
91456485669234603486104543266482133936072602491412
</pre>
<pre>
Unfortunately this is not the correct value!
3.14159265358979323846264338327950288419716939937510582
=================??????????????????????????????????????</pre>
 
=={{header|MiniScript}}==
Calling for 60 digit output does not produce 60 digits of precision. Once the sixteen digit precision of double precision is reached, the subsequent digits are determined by the workings of the binary to decimal conversion. The long decimal string is the exact decimal value of the binary representation of pi, which binary value is itself not exact because pi cannot be represented in a finite number of digits, be they decimal, binary or any other integer base...
Calculate pi using the Rabinowitz-Wagon algorithm
<syntaxhighlight lang="miniscript">digits = input("Enter number of digits to calculate after decimal point: ").val
// I've seen variations of this "precision" calculation from
// 10 * digits
// to
// floor(10 * digits / 3) + 16
// A larger value provides a more precise calculation but also
// takes longer to run. Based on my testing, this calculation
// below for precision produces accurate output for inputs
// from 1 to 4000 - haven't tried larger than this.
precision = floor(10 * digits / 3) + 4
A = [2] * precision
nines = 0
predigit = 0
cnt = 0
while cnt <= digits
carry = 0
for i in range(precision - 1, 1, -1)
temp = 10 * A[i] + carry * i
A[i] = temp % (2 * i - 1)
carry = floor(temp/(2 * i - 1))
end for
A[1] = carry % 10
carry = floor(carry / 10)
current = carry
if current == 9 then
nines += 1
else if current == 10 then
print (predigit+1), ""
cnt += 1
if nines > 0 then
print "9" * nines, ""
cnt += nines
end if
predigit = 0
nines = 0
else
// the first digit produced is always a zero
// don't need to see that
if cnt != 0 then print predigit, ""
cnt += 1
predigit = current
if nines > 0 then
print "9" * nines, ""
cnt += nines
end if
nines = 0
end if
if cnt == 2 then print ".", ""
end while
print str(predigit) * (cnt < digits + 2)</syntaxhighlight>
 
{{out}}
<pre>
Enter number of digits to calculate after decimal point: 1000
3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903690113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051329005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710199031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066139019278766111959092164201989
</pre>
 
=={{header|Nanoquery}}==
{{trans|Java}}
<langsyntaxhighlight Nanoquerylang="nanoquery">q = 1; r = 0; t = 1
k = 1; n = 3; l = 3
 
Line 3,788 ⟶ 4,093:
r = nr
end if
end while</langsyntaxhighlight>
{{out}}
<pre>
Line 3,796 ⟶ 4,101:
=={{header|NetRexx}}==
{{trans|Java}}
<langsyntaxhighlight NetRexxlang="netrexx">/* NetRexx */
options replace format comments java crossref symbols binary
import java.math.BigInteger
Line 3,858 ⟶ 4,163:
method isFalse() private static returns boolean
return \isTrue()
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 3,866 ⟶ 4,171:
=={{header|Nim}}==
{{libheader|bigints}}
<langsyntaxhighlight lang="nim">import bigints
 
var
Line 3,911 ⟶ 4,216:
echo ""
i = 0
eliminateDigit d</langsyntaxhighlight>
 
{{out}}
Line 3,923 ⟶ 4,228:
{{trans|D}}
{{libheader|bignum}}
<langsyntaxhighlight Nimlang="nim">import bignum
 
proc calcPi() =
Line 3,954 ⟶ 4,259:
r = nr
 
calcPi()</langsyntaxhighlight>
 
{{out}}
Line 3,965 ⟶ 4,270:
=={{header|OCaml}}==
The Constructive Real library [http://www.lri.fr/~filliatr/creal.en.html Creal] contains an infinite-precision Pi, so we can just print out its digits.
<langsyntaxhighlight OCamllang="ocaml">open Creal;;
 
let block = 100 in
Line 3,976 ⟶ 4,281:
flush stdout;
incr counter
done</langsyntaxhighlight>
However that is cheating if you want to see an algorithm to generate Pi. Since the Spigot algorithm is already used in the [http://benchmarksgame.alioth.debian.org/u64q/program.php?test=pidigits&lang=ocaml&id=1 pidigits] program, this implements [http://mathworld.wolfram.com/Machin-LikeFormulas.html Machin's formula].
<langsyntaxhighlight OCamllang="ocaml">open Num
 
(* series for: c*atan(1/k) *)
Line 4,020 ⟶ 4,325:
incr npr; shift := !shift */ base;
) else (acc := !acc */ d_acc);
done</langsyntaxhighlight>
 
=={{header|Oforth}}==
 
<langsyntaxhighlight Oforthlang="oforth">: calcPiDigits
| q r t k n l |
1 ->q 0 ->r 1 ->t 1 ->k 3 ->n 3 -> l
Line 4,043 ⟶ 4,348:
k 1+ ->k
]
] ;</langsyntaxhighlight>
 
=={{header|Ol}}==
{{trans|Scheme}}
 
<langsyntaxhighlight lang="scheme">
; 'numbers' is count of numbers or #false for eternal pleasure.
(define (pi numbers)
Line 4,073 ⟶ 4,378:
 
(pi #false)
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 4,091 ⟶ 4,396:
=={{header|PARI/GP}}==
Uses the built-in Brent-Salamin arithmetic-geometric mean iteration.
<langsyntaxhighlight lang="parigp">pi()={
my(x=Pi,n=0,t);
print1("3.");
Line 4,101 ⟶ 4,406:
print1(floor(x*10^n++)%10)
)
};</langsyntaxhighlight>
 
=={{header|Swift}}==
{{works with|Swift 4.2}}
<langsyntaxhighlight lang="swift">
//
// main.swift
Line 4,144 ⟶ 4,449:
k = k - 14
}
</syntaxhighlight>
</lang>
 
=={{header|Pascal}}==
Line 4,150 ⟶ 4,455:
With minor editing changes as published by Stanley Rabinowitz in [http://www.mathpropress.com/stan/bibliography/spigot.pdf].
Minor improvement of <user>Mischi</user> { speedup ~2 ( n=10000 , rumtime 4s-> 1,44s fpc 2.6.4 -O3 }, by calculating only necessary digits up to n.
<langsyntaxhighlight lang="pascal">Program Pi_Spigot;
const
n = 1000;
Line 4,213 ⟶ 4,518:
end;
writeln(predigit);
end.</langsyntaxhighlight>
Output:
<pre>% ./Pi_Spigot
Line 4,224 ⟶ 4,529:
This takes a numer-of-digits argument, but we can make it large (albeit using memory and some startup time). Unlike the other two, this uses no modules and does not require bigints so is worth showing.
 
<langsyntaxhighlight lang="perl">sub pistream {
my $digits = shift;
my(@out, @a);
Line 4,264 ⟶ 4,569:
# We've closed the spigot. Print the remainder without rounding.
print join "", @out[$i-15+4 .. $digits-2], "\n";
}</langsyntaxhighlight>
 
==== Raku spigot ====
Line 4,270 ⟶ 4,575:
 
{{trans|Raku}}
<langsyntaxhighlight lang="perl">use bigint try=>"GMP";
sub stream {
my ($next, $safe, $prod, $cons, $z, $x) = @_;
Line 4,313 ⟶ 4,618:
$|++;
print $pi_stream->(), '.';
print $pi_stream->() while 1;</langsyntaxhighlight>
 
==== Machin's Formula ====
Line 4,319 ⟶ 4,624:
Here is an original Perl 5 code, using Machin's formula. Not the fastest program in the world. As with the previous code, using either Math::GMP or Math::BigInt::GMP instead of the default bigint Calc backend will make it run thousands of times faster.
 
<langsyntaxhighlight Perllang="perl">use bigint try=>"GMP";
 
# Pi/4 = 4 arctan 1/5 - arctan 1/239
Line 4,372 ⟶ 4,677:
$ns /= $g;
}
}</langsyntaxhighlight>
 
==== Modules ====
While no current CPAN module does continuous printing, there are (usually fast) ways to get digits of Pi. Examples include:
{{libheader|ntheory}}
<langsyntaxhighlight lang="perl">
use ntheory qw/Pi/;
say Pi(10000);
Line 4,396 ⟶ 4,701:
use Math::Big qw/pi/; # Very slow
say pi(10000);
</syntaxhighlight>
</lang>
 
=={{header|Phix}}==
I already had this golf entry to hand. Prints 2400 places, change the 8400 (derived from 2400*14/4) as needed, but I've not tested > that.
<!--<langsyntaxhighlight Phixlang="phix">(phixonline)-->
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #004080;">integer</span> <span style="color: #000000;">a</span><span style="color: #0000FF;">=</span><span style="color: #000000;">10000</span><span style="color: #0000FF;">,</span><span style="color: #000000;">b</span><span style="color: #0000FF;">,</span><span style="color: #000000;">c</span><span style="color: #0000FF;">=</span><span style="color: #000000;">8400</span><span style="color: #0000FF;">,</span><span style="color: #000000;">d</span><span style="color: #0000FF;">,</span><span style="color: #000000;">e</span><span style="color: #0000FF;">=</span><span style="color: #000000;">0</span><span style="color: #0000FF;">,</span><span style="color: #000000;">g</span> <span style="color: #004080;">sequence</span> <span style="color: #000000;">f</span><span style="color: #0000FF;">=</span><span style="color: #7060A8;">repeat</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">floor</span><span style="color: #0000FF;">(</span><span style="color: #000000;">a</span><span style="color: #0000FF;">/</span><span style="color: #000000;">5</span><span style="color: #0000FF;">),</span><span style="color: #000000;">c</span><span style="color: #0000FF;">+</span><span style="color: #000000;">1</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">while</span> <span style="color: #000000;">c</span><span style="color: #0000FF;">></span><span style="color: #000000;">0</span> <span style="color: #008080;">do</span> <span style="color: #000000;">g</span><span style="color: #0000FF;">=</span><span style="color: #000000;">2</span><span style="color: #0000FF;">*</span><span style="color: #000000;">c</span> <span style="color: #000000;">d</span><span style="color: #0000FF;">=</span><span style="color: #000000;">0</span>
<span style="color: #000000;">b</span><span style="color: #0000FF;">=</span><span style="color: #000000;">c</span> <span style="color: #008080;">while</span> <span style="color: #000000;">b</span><span style="color: #0000FF;">></span><span style="color: #000000;">0</span> <span style="color: #008080;">do</span> <span style="color: #000000;">d</span><span style="color: #0000FF;">+=</span><span style="color: #000000;">f</span><span style="color: #0000FF;">[</span><span style="color: #000000;">b</span><span style="color: #0000FF;">]*</span><span style="color: #000000;">a</span> <span style="color: #000000;">g</span><span style="color: #0000FF;">-=</span><span style="color: #000000;">1</span> <span style="color: #000000;">f</span><span style="color: #0000FF;">[</span><span style="color: #000000;">b</span><span style="color: #0000FF;">]=</span><span style="color: #7060A8;">remainder</span><span style="color: #0000FF;">(</span><span style="color: #000000;">d</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">g</span><span style="color: #0000FF;">)</span> <span style="color: #000000;">d</span><span style="color: #0000FF;">=</span><span style="color: #7060A8;">floor</span><span style="color: #0000FF;">(</span><span style="color: #000000;">d</span><span style="color: #0000FF;">/</span><span style="color: #000000;">g</span><span style="color: #0000FF;">)</span> <span style="color: #000000;">g</span><span style="color: #0000FF;">-=</span><span style="color: #000000;">1</span> <span style="color: #000000;">b</span><span style="color: #0000FF;">-=</span><span style="color: #000000;">1</span> <span style="color: #008080;">if</span> <span style="color: #000000;">b</span><span style="color: #0000FF;">!=</span><span style="color: #000000;">0</span> <span style="color: #008080;">then</span>
<span style="color: #000000;">d</span><span style="color: #0000FF;">*=</span><span style="color: #000000;">b</span> <span style="color: #008080;">end</span> <span style="color: #008080;">if</span> <span style="color: #008080;">end</span> <span style="color: #008080;">while</span> <span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%04d"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">e</span><span style="color: #0000FF;">+</span><span style="color: #7060A8;">floor</span><span style="color: #0000FF;">(</span><span style="color: #000000;">d</span><span style="color: #0000FF;">/</span><span style="color: #000000;">a</span><span style="color: #0000FF;">))</span> <span style="color: #000000;">c</span><span style="color: #0000FF;">-=</span><span style="color: #000000;">14</span> <span style="color: #000000;">e</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">remainder</span><span style="color: #0000FF;">(</span><span style="color: #000000;">d</span><span style="color: #0000FF;">,</span><span style="color: #000000;">a</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">end</span> <span style="color: #008080;">while</span>
<!--</langsyntaxhighlight>-->
Someone was benchmarking the above against Lua, so I translated the Lua entry, and upped it to 2400 places, for a fairer test.
<!--<langsyntaxhighlight Phixlang="phix">(phixonline)-->
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #004080;">integer</span> <span style="color: #000000;">n</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">2400</span><span style="color: #0000FF;">,</span>
Line 4,441 ⟶ 4,746:
<span style="color: #000000;">res</span> <span style="color: #0000FF;">&=</span> <span style="color: #000000;">predigit</span><span style="color: #0000FF;">+</span><span style="color: #008000;">'0'</span>
<span style="color: #7060A8;">puts</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">res</span><span style="color: #0000FF;">)</span>
<!--</langsyntaxhighlight>-->
 
=={{header|Picat}}==
{{trans|Erlang}}
<langsyntaxhighlight Picatlang="picat">go =>
pi2(1,0,1,1,3,3,0),
nl.
Line 4,466 ⟶ 4,771:
end
end,
nl.</langsyntaxhighlight>
 
{{out}}
Line 4,487 ⟶ 4,792:
=={{header|PicoLisp}}==
The following script uses the spigot algorithm published by Jeremy Gibbons. Hit Ctrl-C to stop it.
<langsyntaxhighlight PicoLisplang="picolisp">#!/usr/bin/picolisp /usr/lib/picolisp/lib.l
 
(de piDigit ()
Line 4,507 ⟶ 4,812:
(loop
(prin (piDigit))
(flush) )</langsyntaxhighlight>
Output:
<pre>3.14159265358979323846264338327950288419716939937510582097494459 ...</pre>
 
=={{header|PL/I}}==
<langsyntaxhighlight PLlang="pl/Ii">/* Uses the algorithm of S. Rabinowicz and S. Wagon, "A Spigot Algorithm */
/* for the Digits of Pi". */
(subrg, fofl, size):
Line 4,553 ⟶ 4,858:
put edit(predigit) (f(1));
end; /* of begin block */
end Pi_Spigot;</langsyntaxhighlight>
output:
<pre>
Line 4,575 ⟶ 4,880:
With some tweaking.
Prints 100 digits a time. Total possible output limited by available memory.
<langsyntaxhighlight lang="powershell">
Function Get-Pi ( $Digits )
{
Line 4,633 ⟶ 4,938:
}
}
</syntaxhighlight>
</lang>
 
Alternate version using .Net classes
<langsyntaxhighlight lang="powershell">
[math]::pi
</syntaxhighlight>
</lang>
Outputs:
<syntaxhighlight lang="text">.Net digits of pi
3.14159265358979
</syntaxhighlight>
</lang>
 
=={{header|Prolog}}==
Using coroutine with freeze/2 predicate:
 
<syntaxhighlight lang="prolog">
<lang Prolog>
pi_spigot :-
pi(X),
Line 4,666 ⟶ 4,971:
I2 is I + 1,
pi(Q2, R2, T2, I2, OUT_)
; true)).</langsyntaxhighlight>
 
=={{header|PureBasic}}==
Calculate Pi, limited to ~24 M-digits for memory and speed reasons.
<langsyntaxhighlight PureBasiclang="purebasic">#SCALE = 10000
#ARRINT= 2000
 
Line 4,709 ⟶ 5,014:
Ctrl:
PrintN(#CRLF$+"Ctrl-C was pressed")
End</langsyntaxhighlight>
 
=={{header|Python}}==
<langsyntaxhighlight Pythonlang="python">def calcPi():
q, r, t, k, n, l = 1, 0, 1, 1, 3, 3
while True:
Line 4,737 ⟶ 5,042:
sys.stdout.write(str(d))
i += 1
if i == 40: print(""); i = 0</langsyntaxhighlight>output
<pre>
3141592653589793238462643383279502884197
Line 4,757 ⟶ 5,062:
 
Quackery does not have variables, it has ancillary stacks. To expedite translation from Oforth, the first two definitions implement words equivalent to the [https://forth-standard.org/standard/core/VALUE Forth words VALUE and TO].
<langsyntaxhighlight Quackerylang="quackery"> [ immovable
]this[ share ]done[ ] is value ( --> x )
Line 4,788 ⟶ 5,093:
L 2 + to L
K 1+ to K ]
chcount again ]</langsyntaxhighlight>
 
{{out}}
Line 4,811 ⟶ 5,116:
 
=={{header|R}}==
<langsyntaxhighlight lang="rsplus">
suppressMessages(library(gmp))
ONE <- as.bigz("1")
Line 4,862 ⟶ 5,167:
}
cat("\n")
</syntaxhighlight>
</lang>
'''Output:'''
<pre>
Line 4,884 ⟶ 5,189:
Utilizing Jeremy Gibbons spigot algorithm and racket generator:
 
<langsyntaxhighlight lang="racket">
#lang racket
(require racket/generator)
Line 4,904 ⟶ 5,209:
(when (zero? i) (display "." ))
(when (zero? (modulo i 80)) (newline)))
</syntaxhighlight>
</lang>
 
Output:
 
<syntaxhighlight lang="text">
3.14159265358979323846264338327950288419716939937510...
</syntaxhighlight>
</lang>
 
=={{header|Raku}}==
(formerly Perl 6)
{{Works with|rakudo|2018.10}}
<syntaxhighlight lang="raku" perl6line># based on http://www.mathpropress.com/stan/bibliography/spigot.pdf
 
sub stream(&next, &safe, &prod, &cons, $z is copy, @x) {
Line 4,947 ⟶ 5,252:
print $pi[$i];
once print '.'
}</langsyntaxhighlight>
 
=={{header|REXX}}==
Line 4,980 ⟶ 5,285:
└─ ─┘
</pre>
<langsyntaxhighlight lang="rexx">/*REXX program spits out decimal digits of pi (one digit at a time) until Ctrl─Break.*/
parse arg digs oFID . /*obtain optional argument from the CL.*/
if digs=='' | digs=="," then digs= 1e6 /*Not specified? Then use the default.*/
Line 5,008 ⟶ 5,313:
say /*stick a fork in it, we're all done. */
exit: say; say n%2+1 'iterations took' format(time("Elapsed"),,2) 'seconds.'; exit 0
halt: say; say 'PI_SPIT halted via use of Ctrl─Break.'; signal exit /*show iterations.*/</langsyntaxhighlight>
{{out|output|text=&nbsp; [until the &nbsp; Ctrl─Break &nbsp; key (or equivalent) was pressed]:}}
 
Line 5,029 ⟶ 5,334:
 
This algorithm is limited to the number of decimal digits as specified with the &nbsp; '''numeric digits ddd''' &nbsp; &nbsp; (line or statement six).
<langsyntaxhighlight lang="rexx">/*REXX program spits out decimal digits of pi (one digit at a time) until Ctrl-Break.*/
signal on halt /*───► HALT when Ctrl─Break is pressed.*/
parse arg digs oFID . /*obtain optional argument from the CL.*/
Line 5,060 ⟶ 5,365:
end /*forever*/
exit /*stick a fork in it, we're all done. */
halt: say; say 'PI_SPIT2 halted via use of Ctrl-Break.'; exit</langsyntaxhighlight> <br><br>
 
=={{header|RPL}}==
It is not easy to print character by character with RPL. Something could be done with the <code>DISP</code> instruction, but it would require to manage the cursor position - and anyway the emulator does not emulate <code>DISP</code> !
===Rabinowitz & Wagon algorithm===
{{trans|BBC Basic}}
There is probably a way to translate the BBC BASIC approach into something that uses only the stack, but it has been preferred here to use 'global' variables with the names used by the BBC BASIC program - except for <code>e</code>, which represents the Euler constant in RPL.
{{works with|Halcyon Calc|4.2.7}}
≪ '''IF''' 1 FS?C '''THEN''' "π = " 'output' STO '''END'''
SWAP →STR '''WHILE''' DUP2 SIZE > '''REPEAT''' "0" SWAP + '''END'''
output SWAP + 'output' STO DROP
'PRINT' STO
≪ → m
≪ 1 SF {} 1 m '''START''' #20d + '''NEXT'''
#0d 'ee' STO #2d 'l' STO
m 14 '''FOR''' c
#0 'd' STO c 2 * 1 - R→B 'a' STO
c 1 '''FOR''' p
DUP p GET 100 * d p * + 'd' STO
p d a / LAST ROT * - PUT
'd' a STO/ 'a' 2 STO-
-1 '''STEP'''
'''IF''' d #99d ==
'''THEN''' ee 100 * d + 'ee' STO #2h 'l' STO+
'''ELSE'''
'''IF''' c m ==
'''THEN'''
d 100 / B→R 10 / 0 PRINT
d 100 / LAST ROT * - 'ee' STO
'''ELSE'''
ee d 100 / + B→R l B→R PRINT
d 100 / LAST ROT * - 'ee' STO #2h 'l' STO
'''END'''
'''END'''
-7 '''STEP'''
DROP output
≫ ≫
'M→π' STO
 
200 M→π
{{out}}
<pre>
1: "π = 3.14159265358979323846264338327950288419716939937510582"
</pre>
=== Faster Rabinowitz & Wagon implementation===
{{trans|Fortran}}
This much faster version favors the stack to local variables.
≪ SWAP →STR
'''IF''' 1 FS?C '''THEN''' "." + '''ELSE WHILE''' DUP2 SIZE > '''REPEAT''' "0" SWAP + '''END''' output SWAP + '''END'''
'output' STO DROP
'WRITE' STO
≪ DUP 50 * 3 / IP → n m
≪ 1 SF 0 {} m + 2 CON 0
1 n '''START'''
DROP 0
m 1 '''FOR''' p
p * OVER p GET 100000 * +
p DUP + 1 - MOD LAST / IP
ROT p 4 ROLL PUT SWAP
-1 '''STEP'''
DUP 100000 MOD LAST / IP
5 ROLL + 5 WRITE
ROT ROT
'''NEXT'''
3 DROPN output
≫ ≫
'N→π' STO
 
100 N→π
{{out}}
<pre>
"3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647093844609550582231725359408128481117450284102701938521105559644622948954930381964428810975665933446128475648233786783165271201909145648566923460348610454326648213393607260249141273724587006606315588174881520920962829254091715364367892590360011330530548820466521384146951941511609433057270365759591953092186117381932611793105118548074462379962749567351885752724891227938183011" </pre>
 
=={{header|Ruby}}==
{{trans|Icon}}
<langsyntaxhighlight lang="ruby">pi_digits = Enumerator.new do |y|
q, r, t, k, n, l = 1, 0, 1, 1, 3, 3
loop do
Line 5,087 ⟶ 5,467:
 
print pi_digits.next, "."
loop { print pi_digits.next }</langsyntaxhighlight>
 
=={{header|Rust}}==
{{trans|Kotlin}}
<langsyntaxhighlight Rustlang="rust">use num_bigint::BigInt;
 
fn main() {
Line 5,127 ⟶ 5,507:
}
}
}</langsyntaxhighlight>
 
=={{header|Scala}}==
<langsyntaxhighlight lang="scala">object Pi {
class PiIterator extends Iterable[BigInt] {
var r: BigInt = 0
Line 5,165 ⟶ 5,545:
}
 
}</langsyntaxhighlight>
Output:
<pre>3.141592653589793238462643383279502884197169399375105820974944592307816406286208998
Line 5,173 ⟶ 5,553:
 
=={{header|Scheme}}==
<langsyntaxhighlight lang="scala">
(import (rnrs))
 
Line 5,204 ⟶ 5,584:
(newline)
(set! i 0))))))
</syntaxhighlight>
</lang>
Output:
<pre>3141592653589793238462643383279502884197
Line 5,225 ⟶ 5,605:
 
=={{header|Seed7}}==
<langsyntaxhighlight lang="seed7">$ include "seed7_05.s7i";
include "bigint.s7i";
 
Line 5,263 ⟶ 5,643:
end if;
end while;
end func;</langsyntaxhighlight>
 
Original source: [http://seed7.sourceforge.net/algorith/math.htm#pi_spigot_algorithm]
Line 5,269 ⟶ 5,649:
=={{header|Sidef}}==
===Classical Algorithm===
<langsyntaxhighlight lang="ruby">func pi(callback) {
var (q, r, t, k, n, l) = (1, 0, 1, 1, 3, 3)
loop {
Line 5,294 ⟶ 5,674:
 
STDOUT.autoflush(true)
pi(func(digit){ print digit })</langsyntaxhighlight>
 
===Quicker, Unverified Algorithm===
{{trans|Haskell}}
From the same .pdf mentioned throughout this task, from the last page. The original algorithm was written in Haskell, this is a translation which has also been optimized to avoid redundant multiplications. Same output, but the algorithm is based on one of Gosper’s series that yields more than one digit per term on average, so no test is made partway through the iteration. This is capable of producing approximately 100,000 digits at [https://tio.run/##Hc@9boNAEATg3k@xnXfvNjaXcEkUa7v0KeLU0fkwP7Zl4DgiIYtnJ4A0xTTfSNNV2Tmfpry/e2jQEzzgzwVsOXDkgi9c8pUdn3ggEEDD5j3h1zU2ZZOssfxCG4BbXTez9zgItgqdluc3Am1VoP3eqkgH6KKLlYffecvjdrddGEAQkygstFy02JTUok9znXGAp2GVrZJSy1VLmhwgKilghHHzffz8@jnuXB/r/NZ3JRr6aHB5gxk9mlDdI2QjTdM/ tio.run] in the maximum 60 seconds allowed.
<langsyntaxhighlight lang="ruby">func p(c) { var(q,r,t,g,j,h,k,a,b,y) = (1,180,60,60,54,10,10,15,3)
loop { c(y=(q*(a+=27) +5*r)//5*t); static _ = c('.')
r=10*(g+=j+=54)*(q*(b+=5) +r -y*t); q*=h+=k+=40; t*=g } }
STDOUT.autoflush(1):p(func(d){print d})</langsyntaxhighlight>
 
=={{header|Simula}}==
<langsyntaxhighlight lang="simula">CLASS BIGNUM;
BEGIN
 
Line 5,613 ⟶ 5,993:
TMOD :- TDIVMOD(A, B).MOD;
 
END BIGNUM;</langsyntaxhighlight><syntaxhighlight lang ="simula">EXTERNAL CLASS BIGNUM;
BIGNUM
BEGIN
Line 5,682 ⟶ 6,062:
 
CALCPI;
END.</langsyntaxhighlight>
Output:
<pre>3141592653589793238462643383279502884197
Line 5,705 ⟶ 6,085:
Used the compact algorithm from [https://www.cs.ox.ac.uk/people/jeremy.gibbons/publications/spigot.pdf Gibbons paper].
Tailspin will at some point have arbitrary precision integers, currently we have to link into java and use BigInteger. Using java code can be slightly awkward as the argument in Tailspin comes before the method, so divide and subtract read backwards.
<langsyntaxhighlight lang="tailspin">
use 'java:java.math' stand-alone
 
Line 5,744 ⟶ 6,124:
 
1 -> g&{q:$one, r:$zero, t:$one, k:$one, n:$three, l:$three} -> !VOID
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 5,753 ⟶ 6,133:
Based on the reference in the [[#D|D]] code.
{{works with|Tcl|8.6}}
<langsyntaxhighlight lang="tcl">package require Tcl 8.6
 
# http://www.cut-the-knot.org/Curriculum/Algorithms/SpigotForPi.shtml
Line 5,783 ⟶ 6,163:
}
}
}</langsyntaxhighlight>
The pi digit generation requires picking a limit to the number of digits; the bigger the limit, the more digits can be ''safely'' computed. A value of 10k yields values relatively rapidly.
<langsyntaxhighlight lang="tcl">coroutine piDigit piDigitsBySpigot 10000
fconfigure stdout -buffering none
while 1 {
puts -nonewline [piDigit]
}</langsyntaxhighlight>
 
=={{header|TypeScript}}==
<langsyntaxhighlight lang="javascript">type AnyWriteableObject={write:((textToOutput:string)=>any)};
 
function calcPi(pipe:AnyWriteableObject) {
Line 5,816 ⟶ 6,196:
}
 
calcPi(process.stdout);</langsyntaxhighlight>
 
'''Notes:'''
Line 5,826 ⟶ 6,206:
=== Async version ===
 
<langsyntaxhighlight lang="javascript">type AnyWriteableObject = {write:((textToOutput:string)=>Promise<any>)};
 
async function calcPi<T extends AnyWriteableObject>(pipe:T) {
Line 5,865 ⟶ 6,245:
});
 
console.log('.'); //start!</langsyntaxhighlight>
 
Here the calculation does not continue if the consumer does not consume the character.
Line 5,875 ⟶ 6,255:
{{works with|VBA|6.5}}
{{works with|VBA|7.1}}
<langsyntaxhighlight lang="vb">Option Explicit
 
Sub Main()
Line 5,909 ⟶ 6,289:
End If
Next n
End Sub</langsyntaxhighlight>
{{out}}
<pre>3.
Line 5,936 ⟶ 6,316:
{{trans|C#}}
Don't forget to use the "'''Project'''" tab, "'''Add Reference...'''" for '''''System.Numerics''''' (in case you get compiler errors in the Visual Studio IDE)
<langsyntaxhighlight lang="vbnet">Imports System
Imports System.Numerics
Line 5,959 ⟶ 6,339:
End Sub
 
End Module</langsyntaxhighlight>
{{out}}
<pre style="height:30ex;overflow:scroll;white-space:pre-wrap;">3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632788659361533818279682303019520353018529689957736225994138912497217752834791315155748572424541506959508295331168617278558890750983817546374649393192550604009277016711390098488240128583616035637076601047101819429555961989467678374494482553797747268471040475346462080466842590694912933136770289891521047521620569660240580381501935112533824300355876402474964732639141992726042699227967823547816360093417216412199245863150302861829745557067498385054945885869269956909272107975093029553211653449872027559602364806654991198818347977535663698074265425278625518184175746728909777727938000816470600161452491921732172147723501414419735685481613611573525521334757418494684385233239073941433345477624168625189835694855620992192221842725502542568876717904946016534668049886272327917860857843838279679766814541009538837863609506800642251252051173929848960841284886269456042419652850222106611863067442786220391949450471237137869609563643719172874677646575739624138908658326459958133904780275900994657640789512694683983525957098258226205224894077267194782684826014769909026401363944374553050682034962524517493996514314298091906592509372216964615157098583874105978859597729754989301617539284681382686838689427741559918559252459539594310499725246808459872736446958486538367362226260991246080512438843904512441365497627807977156914359977001296160894416948685558484063534220722258284886481584560285060168427394522674676788952521385225499546667278239864565961163548862305774564980355936345681743241125150760694794510965960940252288797108931456691368672287489405601015033086179286809208747609178249385890097149096759852613655497818931297848216829989487226588048575640142704775551323796414515237462343645428584447952658678210511413547357395231134271661021359695362314429524849371871101457654035902799344037420073105785390621983874478084784896833214457138687519435064302184531910484810053706146806749192781911979399520614196634287544406437451237181921799983910159195618146751426912397489409071864942319615679452080951465502252316038819301420937621378559566389377870830390697920773467221825625996615014215030680384477345492026054146659252014974428507325186660021324340881907104863317346496514539057962685610055081066587969981635747363840525714591028970641401109712062804390397595156771577004203378699360072305587631763594218731251471205329281918261861258673215791984148488291644706095752706957220917567116722910981690915280173506712748583222871835209353965725121083579151369882091444210067510334671103141267111369908658516398315019701651511685171437657618351556508849099898599823873455283316355076479185358932261854896321329330898570642046752590709154814165498594616371802709819943099244889575712828905923233260972997120844335732654893823911932597463667305836041428138830320382490375898524374417029132765618093773444030707469211201913020330380197621101100449293215160842444859637669838952286847831235526582131449576857262433441893039686426243410773226978028073189154411010446823252716201052652272111660396665573092547110557853763466820653109896526918620564769312570586356620185581007293606598764861179104533488503461136576867532494416680396265797877185560845529654126654085306143444318586769751456614068007002378776591344017127494704205622305389945613140711270004078547332699390814546646458807972708266830634328587856983052358089330657574067954571637752542021149557615814002501262285941302164715509792592309907965473761255176567513575178296664547791745011299614890304639947132962107340437518957359614589019389713111790429782856475032031986915140287080859904801094121472213179476477726224142548545403321571853061422881375850430633217518297986622371721591607716692547487389866549494501146540628433663937900397692656721463853067360965712091807638327166416274888800786925602902284721040317211860820419000422966171196377921337575114959501566049631862947265473642523081770367515906735023507283540567040386743513622224771589150495309844489333096340878076932599397805419341447377441842631298608099888687413260472156951623965864573021631598193195167353812974167729478672422924654366800980676928238280689964004824354037014163149658979409243237896907069779422362508221688957383798623001593776471651228935786015881617557829735233446042815126272037343146531977774160319906655418763979293344195215413418994854447345673831624993419131814809277771038638773431772075456545322077709212019051660962804909263601975988281613323166636528619326686336062735676303544776280350450777235547105859548702790814356240145171806246436267945612753181340783303362542327839449753824372058353114771199260638133467768796959703098339130771098704085913374641442822772634659470474587847787201927715280731767907707157213444730605700733492436931138350493163128404251219256517980694113528013147013047816437885185290928545201165839341965621349143415956258658655705526904965209858033850722426482939728584783163057777560688876446248246857926039535277348030480290058760758251047470916439613626760449256274204208320856611906254543372131535958450687724602901618766795240616342522577195429162991930645537799140373404328752628889639958794757291746426357455254079091451357111369410911939325191076020825202618798531887705842972591677813149699009019211697173727847684726860849003377024242916513005005168323364350389517029893922334517220138128069650117844087451960121228599371623130171144484640903890644954440061986907548516026327505298349187407866808818338510228334508504860825039302133219715518430635455007668282949304137765527939751754613953984683393638304746119966538581538420568533862186725233402830871123282789212507712629463229563989898935821167456270102183564622013496715188190973038119800497340723961036854066431939509790190699639552453005450580685501956730229219139339185680344903982059551002263535361920419947455385938102343955449597783779023742161727111
Line 5,965 ⟶ 6,345:
===Quicker, unverified algo===
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.
<langsyntaxhighlight lang="vbnet">Imports System, System.Numerics, System.Text
Module Module1
Line 6,000 ⟶ 6,380:
If Diagnostics.Debugger.IsAttached Then Console.ReadKey()
End Sub
End Module</langsyntaxhighlight>
{{out}}The First several thousand digits verified the same as the conventional spigot algorithm, haven't detected any differences yet.
<pre style="height:30ex;overflow:scroll;white-space:pre-wrap;">Press a key to exit...
Line 6,009 ⟶ 6,389:
{{trans|Kotlin}}
{{libheader|Wren-big}}
<syntaxhighlight lang=ecmascript"wren">import "./big" for BigInt
import "io" for Stdout
 
Line 6,056 ⟶ 6,436:
=={{header|Yabasic}}==
{{trans|BASIC256}}
<syntaxhighlight lang="yabasic">n = 1000
long = 10 * int(n / 4)
needdecimal = 1 //true
Line 6,122 ⟶ 6,502:
Uses the GMP big int library.
Same algorithm as many of the others on this page. Uses in place ops to cut down on big int generation (eg add vs +). Unless GC is given some hints, it will use up 16 gig quickly as it outruns the garbage collector.
<syntaxhighlight lang="zkl">var [const] BN=Import("zklBigNum"),
one=BN(1), two=BN(2), three=BN(3), four=BN(4), seven=BN(7), ten=BN(10);
 
9,476

edits