From 5046209659500c82329774fbfd4d6f400e90b8e2 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Mon, 5 Dec 2022 19:22:33 +0200 Subject: [math] Added a power and an avg function --- src/math.lisp | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src') diff --git a/src/math.lisp b/src/math.lisp index 06931ff..832c87c 100644 --- a/src/math.lisp +++ b/src/math.lisp @@ -31,3 +31,16 @@ (defmacro *= (value &rest numbers) "Multiplies all numbers and stores result in name (first argument)" `(op= '* ,value ,@numbers)) + +(defun ^ (number power) + "Calculates number to the power" + (let ((prod 1)) + (dotimes (x power) + (setq prod (* prod number))) + prod)) + +(defun avg (&rest numbers) + "Calculates the average of all given numbers. If no numbers are given, returns 0." + (if (not numbers) + 0 + (/ (apply '+ numbers) (length numbers)))) -- cgit v1.2.3