Arithmetic/Integer: Difference between revisions

→‎{{header|Common Lisp}}: Rewritten to fit task description.
(→‎{{header|Common Lisp}}: Rewritten to fit task description.)
Line 124:
=={{header|Common Lisp}}==
 
<lang lisp>(defun arithmetic (&aux (a (read *query-io*)) (b (read *query-io*)))
(mapc
(let ((a (read *query-io*)) (b (read *query-io*)))
(formatlambda t(op "a&aux +(form b(list = ~a~%" (+op a b)))
(format t "~a - b => ~a~%" (-form a(eval bform)))
'(format+ t "a- * bmod =rem ~a~%"floor (*ceiling atruncate bround expt)))</lang>
 
(format t "a / b = ~a~%" (/ a b))
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.
(format t "a % b = ~a~%" (mod a b))))</lang>
 
{| class="wikitable"
! The function !! rounds its quotient towards
|-
! <code>floor</code>
| negative infinity
|-
! <code>ceiling</code>
| positive infinity
|-
! <code>truncate</code>
| zero
|-
! <code>round</code>
| the nearest integer (preferring the even integer if the mathematical quotient is equidistant from two integers)
|}
 
Each function also returns a remainder as its secondary value, such that
quotient * divisor + remainder = dividend .
<code>(mod a b)</code> and <code>(rem a b)</code> return numbers equal to the secondary values of <code>(floor a b)</code> and <code>(truncate a b)</code>, respectively.
 
=={{header|D}}==
845

edits