fixnum-width, least-fixnum, greatest-fixnum - query the fixnum range
(import (rnrs)) ;R6RS
(import (rnrs arithmetic fixnums)) ;R6RS
The fixnum range is defined as the closed interval
such that w is an implementation-defined integer w ≥ 24.
procedure returns the implementation's w.
procedure returns −2^(w−1).
procedure returns 2^(w−1)−1.
The fixnum range is important to consider when using the fixnum
procedures because these procedures require that their arguments and
results are fixnums. They raise an exception when a result cannot be
represented as a fixnum.
The fixnum width depends very much on implementation details and the
machine. Here are some known fixnum widths.
- Chez Scheme
The fixnum width is 61 or 30. If the machine's register width is
m then the fixnum width is m - log2(m/8).
- GNU Guile
The fixnum width is 62 or 30. This is the machine's register width
The fixnum width is 32.
- Loko Scheme
The fixnum width is 61.
These procedures each return a single value; a fixnum as per the
; The results are different for different implementations.
(fixnum-width) => 61
(least-fixnum) => -1152921504606846976
(greatest-fixnum) => 1152921504606846975
This procedure is sometimes used in libraries that provide optimized
variants of code for implementations where the fixnum width is large
If the fixnum width is 32 (or greater) then fixnums can represent all
signed 32-bit integers.
This procedure is only present in R6RS. An alternative to
(fixnum-width) is (+ 1 (bitwise-length
(greatest-fixnum))). But normally there is no need to use fixnum
procedures if they are not available; generic arithmetic can be used
instead and will give the same results.
This procedure can raise exceptions with the following condition types:
- &assertion (R6RS)
The wrong number of arguments was passed.
These procedures are new to the fixnum library in R6RS.
Implementations have always had some kind of fixnum type but was
normally not seen by the user.
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.