The
| the result of runding the result of number divided by divisor | ||
| the remainder of the round operation |
(defun cl:round (number &optional (divisor
(if (integerp number) 1 1.0)
divisor-p))
(let* ((x (/ (float number) divisor))
(quotient (cond ((and (not divisor-p) (integerp number)) number)
((= number divisor) 1)
((plusp x) (truncate (+ x 0.5)))
((= (- x 0.5) (truncate (- x 0.5)))
(if (minusp x)
(1- (truncate x))
(truncate x)))
(t (truncate (- x 0.5))))))
(setq *rslt* (list quotient (- number (* quotient divisor)))
cl:*multiple-values* t)
quotient))
The
The quotient is directly returned by the function, while a list:
(quotient remainder)
is stored in the Nyquist/XLISP *rslt* variable and the cl:*multiple-values* is set to T to signal that Multiple Values are returned.
Examples:
(round 3.5) => 4 (round -3.5) => -3 (cl:round 3.5) => 4 ; *rslt* = ( 4 -0.5) (cl:round -3.5) => -4 ; *rslt* = (-4 0.5)