Sha256: 316be0f631f4b9261732e815974c7aae8d1c06fe4f77a52be7de9705237ae222
Contents?: true
Size: 1.03 KB
Versions: 10
Compression:
Stored size: 1.03 KB
Contents
(defun arithmetic (&optional (a (read *query-io*)) (b (read *query-io*))) (mapc (lambda (op) (format t "~a => ~a~%" (list op a b) (funcall (symbol-function op) a b))) '(+ - * mod rem floor ceiling truncate round expt)) (values)) 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.
Version data entries
10 entries across 7 versions & 1 rubygems