picolisp

Unnamed repository; edit this file to name it for gitweb.
git clone https://logand.com/git/picolisp.git/
Log | Files | Refs | README | LICENSE

commit 7bf79f816239f334e6f4d9554f66371d4c843f19
parent 51e91691f1f61a15bc412986faa0694a6f60f02d
Author: Alexander Burger <abu@software-lab.de>
Date:   Wed,  4 May 2011 18:20:15 +0200

Added unbounded PI digit stream generation
Diffstat:
Mmisc/pi.l | 27++++++++++++++++++++++++++-
1 file changed, 26 insertions(+), 1 deletion(-)

diff --git a/misc/pi.l b/misc/pi.l @@ -1,4 +1,4 @@ -# 14aug05abu +# 03may11abu # (c) Software Lab. Alexander Burger ############################## @@ -21,3 +21,28 @@ (test 3141592653589793238462643383279502884197169399375105820975043 (pi 60) ) + + +################################### +# Spigot algorithm (Jeremy Gibbons) +# Print next digit of PI (unbounded) + +(de piDigit () + (job '((Q . 1) (R . 0) (S . 1) (K . 1) (N . 3) (L . 3)) + (while (>= (- (+ R (* 4 Q)) S) (* N S)) + (mapc set '(Q R S K N L) + (list + (* Q K) + (* L (+ R (* 2 Q))) + (* S L) + (inc K) + (/ (+ (* Q (+ 2 (* 7 K))) (* R L)) (* S L)) + (+ 2 L) ) ) ) + (prog1 N + (let M (- (/ (* 10 (+ R (* 3 Q))) S) (* 10 N)) + (setq Q (* 10 Q) R (* 10 (- R (* N S))) N M) ) ) ) ) + +(prin (piDigit) ".") +(loop + (prin (piDigit)) + (flush) )