The
the result of truncating the result of number divided by divisor | ||
the remainder of the truncate operation |
(defun cl:truncate (number &optional (divisor (if (integerp number) 1 1.0))) (let ((quotient (truncate (/ (float number) divisor)))) (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:
(cl:truncate 3.5) => 0 ; *rslt* => ( 3 0.5) (cl:truncate -3.5) => -3 ; *rslt* => (-3 -0.5)
Force an integer division:
(cl:truncate 3.1 2.6) => 1 ; *rslt* => (1 0.5) (/ 3 2) => 1