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

ceiling


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

(ceiling number)
number - an integer or floating-point expression
returns - the integer result of truncating number

(defun ceiling (number)
  (let ((trunc (truncate number)))
    (if (or (minusp number) (= number trunc))
        trunc
        (1+ trunc))))

The 'ceiling' function computes an integer number that has been truncated toward positive infinity. That is, the result represents the smallest mathematical integer that is not smaller than the number given as argument.

Examples:

(ceiling 3)    => 3      (ceiling -3)    => -3
(ceiling 3.0)  => 3      (ceiling -3.0)  => -3
(ceiling 3.1)  => 4      (ceiling -3.1)  => -3
(ceiling 3.5)  => 4      (ceiling -3.5)  => -3
(ceiling 3.9)  => 4      (ceiling -3.9)  => -3
(ceiling 4.0)  => 4      (ceiling -4.0)  => -4

  Back to top


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