absolute value conditional
Posted: Sun Oct 16, 2011 8:12 am
Hi,
I wrote the following 2 functions to return the absolute value of a number. They seem to work but If you could have a look and point out any mistakes in style, design, efficiency, etc.
Thank you.
I wrote the following 2 functions to return the absolute value of a number. They seem to work but If you could have a look and point out any mistakes in style, design, efficiency, etc.
Code: Select all
(defun absvalue (n)
"Returns the absolute value of the argument"
(if (numberp n)
(if (< n 0) (- n) n)
'it-is-not-a-number))
(defun absval2 (n)
"An alternative version of absvalue"
(cond ((and (numberp n) (< n 0)) (- n))
((numberp n) n)
('we-need-numbers)))