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

floor


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

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

(defun floor (number)
  (let ((trunc (truncate number)))
    (if (or (plusp number) (= number trunc))
        trunc
        (1- trunc))))

The 'floor' function computes an integer number that has been truncated toward negative infinity. That is, the result represents the largest mathematical integer that is not larger than the number given as argument.

Examples:

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

  Back to top


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