fixnum-width, least-fixnum, greatest-fixnum - query the fixnum range
LIBRARY
(import (rnrs)) ;R6RS
(import (rnrs arithmetic fixnums)) ;R6RS
SYNOPSIS
(fixnum-width)
(least-fixnum)
(greatest-fixnum)
DESCRIPTION
The fixnum range is defined as the closed interval
[−2^(w−1), 2^(w−1)−1]
such that w is an implementation-defined integer w ≥ 24.
The
fixnum-width
procedure returns the implementation's w.
The
least-fixnum
procedure returns −2^(w−1).
The
greatest-fixnum
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.
IMPLEMENTATION NOTES
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
minus two.
- IronScheme
-
The fixnum width is 32.
- Loko Scheme
-
The fixnum width is 61.
RETURN VALUES
These procedures each return a single value; a fixnum as per the
description above.
EXAMPLES
; The results are different for different implementations.
(fixnum-width) => 61
(least-fixnum) => -1152921504606846976
(greatest-fixnum) => 1152921504606846975
APPLICATION USAGE
This procedure is sometimes used in libraries that provide optimized
variants of code for implementations where the fixnum width is large
enough.
If the fixnum width is 32 (or greater) then fixnums can represent all
signed 32-bit integers.
COMPATIBILITY
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.
ERRORS
This procedure can raise exceptions with the following condition types:
- &assertion (R6RS)
-
The wrong number of arguments was passed.
SEE ALSO
bitwise-length(3scm)
STANDARDS
R6RS
HISTORY
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.
AUTHORS
This page is part of the
scheme-manpages
project.
It includes materials from the RnRS documents.
More information can be found at
https://github.com/schemedoc/manpages/
.
Markup created by unroff 1.0sc, March 04, 2023.