| round(3scm) | Scheme Programmer's Manual | round(3scm) |
NAME
ceiling, floor, round, truncate - round a numberLIBRARY
(import (rnrs)) ;R6RS (import (rnrs base)) ;R6RS (import (scheme r5rs)) ;R7RS (import (scheme base)) ;R7RS (import (rnrs arithmetic flonums)) ;R6RS
SYNOPSIS
(ceiling x) (floor x) (round x) (truncate x) (flceiling fl) (flfloor fl) (flround fl) (fltruncate fl)
DESCRIPTION
These procedures return inexact integer objects for inexact arguments that are not infinities or NaNs, and exact integer objects for exact rational arguments.- ceiling
- Returns the smallest integer object not smaller than x.
- floor
- Returns the largest integer object not larger than x.
- round
- Returns the closest integer object to x, rounding to even when x represents a number halfway between two integers.
- truncate
- Returns the integer object closest to x whose absolute value is not larger than the absolute value of x.
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.
RETURN VALUES
Returns a single number object that is an integer, an infinity or a NaN.EXAMPLES
(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
RATIONALE
round(3scm) rounds to even for consistency with the default rounding mode specified by the IEEE 754 floating-point standard.ERRORS
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.
- R7RS
- 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.
SEE ALSO
rationalize(3scm), div-and-mod(3scm), exact(3scm)STANDARDS
R4RS, IEEE Scheme, R5RS, R6RS, R7RSHISTORY
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.AUTHORS
This page is part of the scheme-manpages project. It includes materials from the RnRS documents. More information can be found at https://weinholt.se/scheme/manpages/.| 2022-03-27 |