File: floor

package info (click to toggle)
scheme9 2025.08.12-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,080 kB
  • sloc: lisp: 16,752; ansic: 11,869; sh: 806; makefile: 237; sed: 6
file content (28 lines) | stat: -rw-r--r-- 1,049 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
R4RS 6.5.5  (floor number)     ==>  integer
            (ceiling number)   ==>  integer
            (truncate number)  ==>  integer
            (round number)     ==>  integer

FLOOR returns the largest integer not larger than NUMBER. CEILING
returns the smallest integer not smaller than NUMBER. TRUNCATE
returns the integer closest to NUMBER whose absolute value is not
larger than the absolute value of NUMBER. ROUND returns the closest
integer to NUMBER, rounding to even when NUMBER 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