aboutsummaryrefslogtreecommitdiff
path: root/src/math.lisp
diff options
context:
space:
mode:
authorSyndamia <kamen@syndamia.com>2022-12-05 19:22:33 +0200
committerSyndamia <kamen@syndamia.com>2022-12-05 19:22:33 +0200
commit5046209659500c82329774fbfd4d6f400e90b8e2 (patch)
treeba927eb729a7f45d11b4e087a8d8d17ae9821232 /src/math.lisp
parenta869c5c09514e6a129e861fd76d8b538f70aa617 (diff)
downloadsenzill-5046209659500c82329774fbfd4d6f400e90b8e2.tar
senzill-5046209659500c82329774fbfd4d6f400e90b8e2.tar.gz
senzill-5046209659500c82329774fbfd4d6f400e90b8e2.zip
[math] Added a power and an avg function
Diffstat (limited to 'src/math.lisp')
-rw-r--r--src/math.lisp13
1 files changed, 13 insertions, 0 deletions
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))))