chickadee » scheme » ceiling

floor xprocedure
ceiling xprocedure
truncate xprocedure
round xprocedure

These procedures return integers. Floor returns the largest integer not larger than x. Ceiling returns the smallest integer not smaller than x. Truncate returns the integer closest to x whose absolute value is not larger than the absolute value of x. Round returns the closest integer to x, rounding to even when x is halfway between two integers.

Rationale: Round rounds to even for consistency with the default rounding mode specified by the IEEE floating point standard.

Note: If the argument to one of these procedures is inexact, then the result will also be inexact. If an exact value is needed, the result should be passed to the inexact->exact procedure.

(floor -4.3)                  ===>  -5.0
(ceiling -4.3)                ===>  -4.0
(truncate -4.3)               ===>  -4.0
(round -4.3)                  ===>  -4.0

(floor 3.5)                   ===>  3.0
(ceiling 3.5)                 ===>  4.0
(truncate 3.5)                ===>  3.0
(round 3.5)                   ===>  4.0  ; inexact

(round 7/2)                   ===>  4    ; exact
(round 7)                     ===>  7