picolisp

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

piDigits.l (734B)


      1 # 16jun11abu
      2 # (c) Software Lab. Alexander Burger
      3 
      4 # Spigot algorithm (Jeremy Gibbons)
      5 
      6 # Print next digit of PI (unbounded)
      7 (de piDigit ()
      8    (job '((Q . 1) (R . 0) (S . 1) (K . 1) (N . 3) (L . 3))
      9       (while (>= (- (+ R (* 4 Q)) S) (* N S))
     10          (mapc set '(Q R S K N L)
     11             (list
     12                (* Q K)
     13                (* L (+ R (* 2 Q)))
     14                (* S L)
     15                (inc K)
     16                (/ (+ (* Q (+ 2 (* 7 K))) (* R L)) (* S L))
     17                (+ 2 L) ) ) )
     18       (prog1 N
     19          (let M (- (/ (* 10 (+ R (* 3 Q))) S) (* 10 N))
     20             (setq Q (* 10 Q)  R (* 10 (- R (* N S)))  N M) ) ) ) )
     21 
     22 # Print _all_ digits of PI
     23 (prin (piDigit) ".")
     24 (loop
     25    (prin (piDigit))
     26    (flush) )
     27 
     28 # vi:et:ts=3:sw=3