On Thu, Feb 13, 2025 at 07:38:10AM +0100, Alexander Burger wrote:
> When I built the tco version yesterday, I experimended with both
> versions, and somehow the 'M' code was lost :(
OK, I will settle with this version:
# Print next digit of PI
(de digit (Env)
(job Env
(tco (Q R S K N L)
(if (>= (- (+ R (* 4 Q)) S) (* N S))
(tc
(* 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) ) ) ) ) )
# Print 'N' or all digits of PI
(de pi (N)
(let E (env 'Q 1 'R 0 'S 1 'K 1 'N 3 'L 3)
(prin (digit E) ".")
(do (or N T)
(prin (digit E))
(flush) ) )
(prinl) )
The 'job' environment is factored out of 'digit' so that 'pi' can be
restarted like:
$ ./pil misc/pi.l +
: (pi 7)
3.1415926
-> NIL
: (pi 30)
3.141592653589793238462643383279
-> NIL
: (pi)
3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669...
☺/ A!ex
--
UNSUBSCRIBE: mailto:[email protected]?subject=Unsubscribe