ceiling, floor, round, truncate - round a number
(import (rnrs)) ;R6RS
(import (rnrs base)) ;R6RS
(import (scheme r5rs)) ;R7RS
(import (scheme base)) ;R7RS
(import (rnrs arithmetic flonums)) ;R6RS
These procedures return inexact integer objects for inexact
arguments that are not infinities or NaNs, and exact integer
objects for exact rational arguments.
Returns the smallest integer object not smaller than
Returns the largest integer object not larger than
Returns the closest integer object to
rounding to even when
represents a number halfway between two integers.
Returns the integer object closest to
whose absolute value is not larger
than the absolute value of
If the argument to one of these procedures is inexact, then the result
is also inexact.
Although infinities and NaNs are not integer objects, these
procedures return an infinity when given an infinity as an
argument, and a NaN when given a NaN.
The flonum variants work as described above, but the argument and
return value is always a flonum.
Returns a single number object that is an integer, an infinity or a
(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
(round 7/2) => 4
(round 7) => 7
(floor +inf.0) => +inf.0
(ceiling -inf.0) => -inf.0
(round +nan.0) => +nan.0
(flfloor +inf.0) => +inf.0
(flceiling -inf.0) => -inf.0
(fltruncate +nan.0) => +nan.0
rounds to even for consistency with the default rounding mode
specified by the IEEE 754 floating-point standard.
This procedure can raise exceptions with the following condition types:
- &assertion (R6RS)
The wrong number of arguments was passed or an argument was outside its domain.
The assertions described above are errors.
Implementations may signal an error, extend the procedure's
domain of definition to include such arguments,
or fail catastrophically.
These procedures first appeared in R2RS, which based them on similar
functions in Common Lisp. Note that the Common Lisp versions have a
second return value.
This page is part of the
It includes materials from the RnRS documents.
More information can be found at
Markup created by unroff 1.0sc, March 04, 2023.