Arithmetic/Integer: Difference between revisions
→{{header|Common Lisp}}: Rewritten to fit task description.
m (→{{header|Tcl}}) |
Underscore (talk | contribs) (→{{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
(
(format t "~a
'(
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.
{| 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}}==
|