Nyquist / XLISP 2.0  -  Contents | Tutorials | Examples | Reference

cl:floor


The cl:floor function truncates an integer or floating-point number toward negative infinity:

(cl:floor number [divisor])
number - an integer or floating-point number
divisor - an integer or floating-point number, except zero
returns  -  the result of truncating the result of number divided by divisor
 -  the remainder of the truncate operation

(defun cl:floor (number &optional (divisor
                                  (if (integerp number) 1 1.0)
                                  divisor-p))
  (let ((quotient
          (cond ((and (not divisor-p) (integerp number)) number)
                ((= number divisor) 1)
                (t (let ((i-quotient (/ (truncate number) (truncate divisor)))
                         (f-quotient (/ (float number) divisor)))
                     (if (or (= i-quotient f-quotient)  ; integer result
                             (not (minusp f-quotient)))
                          (truncate f-quotient)
                          (1- (truncate f-quotient))))))))
    (setq *rslt* (list quotient (- number (* quotient divisor)))
          cl:*multiple-values* t)
    quotient))

The cl:floor function computes a quotient that has been truncated toward negative infinity. That is, the quotient represents the largest mathematical integer that is not larger than the mathematical quotient.

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.

See Rounding and Truncation for more details.

Examples:

(cl:floor  3.5)  =>  3  ; *rslt* => ( 3 0.5)
(cl:floor -3.5)  => -4  ; *rslt* => (-4 0.5)

See also:

  Back to top


Nyquist / XLISP 2.0  -  Contents | Tutorials | Examples | Reference