mirror of
https://github.com/vinc/moros.git
synced 2024-06-18 15:07:08 +00:00
* Add bigint support to Lisp * Remove Box * Replace BigInt by i64 * Add back big int * Work around big int errors * Print floats with a dot * Add conversion to f64 * Use Number#parse instead of double * Add trigo functions to Number * Add conversion from number to byte * Add addition to Number * Add multiplication to Number * Add negation and substraction to Number * Add division to Number * Add reminder to Number * Add pow to Number * Fix tests * Re-enable BigInt * Add parsing and printing of BigInt * Add sign * Add operations on BigInt * Fix compilation issues * Add support for add and mul overflow * Fix bigint conversion to and from str * Add number-type function * Add tests * Add support for pow overflow * Fix tests * Add more checks for overflow * Add check for division by zero * Fix typo * Return inf for large exponential operations * Check for division by zero in modulo * Add shift operations * Rewrite comparisons * Add lazy eval to cond expressions * Add set fonction * Add loop function * Add pi example * Add builtin pi example to shell * Update allocation error messages * Rewrite number conversions * Remove debug output from pi example * Move pi command to a dedicated file * Rewrite bytes->number and number->bytes * Update doc * Move op impl to Number * Add macros to dry code * Add more macros * Run clippy
39 lines
987 B
Plaintext
39 lines
987 B
Plaintext
(load "/lib/lisp/core.lsp")
|
|
|
|
(define (pi-digits y)
|
|
(do
|
|
(define dot true)
|
|
(define q 1)
|
|
(define r 0)
|
|
(define t 1)
|
|
(define k 1)
|
|
(define n 3)
|
|
(define l 3)
|
|
(map
|
|
(lambda (j)
|
|
(do
|
|
(cond
|
|
((< (- (+ (* q 4) r) t) (* n t)) (do
|
|
(print (string n (cond (dot ".") (true ""))))
|
|
(set dot false)
|
|
(define nr (* 10 (- r (* n t))))
|
|
(set n (- (/ (* 10 (+ (* 3 q) r)) t) (* 10 n)))
|
|
(set q (* q 10))
|
|
(set r nr)))
|
|
(true (do
|
|
(define nr (* (+ (* 2 q) r) l))
|
|
(define nn (/ (+ 2 (* q k 7) (* r l)) (* t l)))
|
|
(set q (* q k))
|
|
(set t (* t l))
|
|
(set l (+ l 2))
|
|
(set k (+ k 1))
|
|
(set n nn)
|
|
(set r nr))))))
|
|
(range 0 y))
|
|
n))
|
|
|
|
(println
|
|
(cond
|
|
((nil? args) "Usage: pi <precision>")
|
|
(true (pi-digits (string->number (car args))))))
|