; uLisp Infinite Precision Package Version 2 - 13th May 2021 ; see http://www.ulisp.com/show?1FHA ; ; Convert an integer to big format (defun big (n) (cond ((< n 100) (list n)) (t (cons (mod n 100) (big (truncate n 100)))))) ; Print a big number (defun pri (n) (let ((rn (reverse n))) (format t "~d~{~2,'0d~}" (car rn) (cdr rn)))) ; + for big numbers (defun add (a b) (cond ((null a) b) ((null b) a) (t (put (+ (car a) (car b)) (add (cdr a) (cdr b)))))) (defun put (n c) (cond ((< n 100) (cons n c)) (t (cons (mod n 100) (add (list (truncate n 100)) c))))) ; * for big numbers (defun mul (a b) (cond ((null a) nil) ((null b) nil) (t (add (list (* (car a) (car b))) (cons 0 (add (add (mul (list (car a)) (cdr b)) (mul (cdr a) (list (car b)))) (let ((c (mul (cdr a) (cdr b)))) (when c (cons 0 c))))))))) ; Factorial n (defun fac (n) (let ((f (big 1))) (dotimes (x n) (setq f (mul f (big (1+ x))))) (pri f) (print nothing))) ; Integer exponent - x^y (defun iex (x y) (let ((e (big 1)) (f (big x))) (loop (when (zerop y) (return)) (when (oddp y) (setq e (mul e f))) (setq f (mul f f) y (ash y -1))) (pri e) (print nothing)))