Arithmetic/Integer: Difference between revisions

Content added Content deleted
(→‎TI-89 BASIC: new example)
(don't use EVAL)
Line 173: Line 173:
=={{header|Common Lisp}}==
=={{header|Common Lisp}}==


<lang lisp>(defun arithmetic (&aux (a (read *query-io*)) (b (read *query-io*)))
<lang lisp>(defun arithmetic (&optional (a (read *query-io*)) (b (read *query-io*)))
(mapc
(mapc
(lambda (op &aux (form (list op a b)))
(lambda (op)
(format t "~a => ~a~%" form (eval form)))
(format t "~a => ~a~%" (list op a b) (funcall (symbol-function op) a b)))
'(+ - * mod rem floor ceiling truncate round expt)))</lang>
'(+ - * mod rem floor ceiling truncate round expt))
(values))</lang>


Common Lisp's integer division functions are <code>floor</code>, <code>ceiling</code>, <code>truncate</code>, and <code>round</code>. They differ in how they round their quotient.
Common Lisp's integer division functions are <code>floor</code>, <code>ceiling</code>, <code>truncate</code>, and <code>round</code>. They differ in how they round their quotient.