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

cl:ceiling


The cl:ceiling function truncates an integer or floating-point number toward positive infinity:

(cl:ceiling 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:ceiling (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 (plusp f-quotient)))
                          (truncate f-quotient)
                          (1+ (truncate f-quotient))))))))
    (setq *rslt* (list quotient (- number (* quotient divisor)))
          cl:*multiple-values* t)
    quotient))

The cl:ceiling function computes a quotient that has been truncated toward positive infinity. That is, the quotient represents the smallest mathematical integer that is not smaller than the mathematical result.

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:ceiling  3.5)  =>  4  ; *rslt* => ( 4 -0.5)
(cl:ceiling -3.5)  => -3  ; *rslt* => (-3 -0.5)

  Back to top


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