User:Eriksiers/Alternate CLISP exponentiation: Difference between revisions

m
updated lang tag
m (added footnote to Ahungry's example)
m (updated lang tag)
 
Line 1:
This is a better example of exponent (it doesn't solve for negatives however so I will leave in tact the other example):
 
<langsyntaxhighlight lang="lisp">
(defun ^ (a b)
(let ((r 1))
(dotimes (x b r)
(setf r (* r a)))))
</syntaxhighlight>
</lang>
 
<small>(The above example is by [[User:Ahungry|Ahungry]].)</small>
Line 16:
Later, I might update this to handle [[Nth root|b as a float]].
 
<langsyntaxhighlight lang="lisp">; calculates a to the bth power (a^b)
; b must be an integer
; a can be integer or floating-point
Line 39:
)
)
)</langsyntaxhighlight>
 
Sample outputs:
1,150

edits