4.2.4 Fixnums
(require racket/fixnum) | package: base |
The racket/fixnum library provides operations like fx+ that consume and produce only fixnums. The operations in this library are meant to be safe versions of unsafe operations like unsafe-fx+. These safe operations are generally no faster than using generic primitives like +.
The expected use of the racket/fixnum library is for code where the require of racket/fixnum is replaced with
(require (filtered-in (λ (name) (and (regexp-match #rx"^unsafe-fx" name) (regexp-replace #rx"unsafe-" name ""))) racket/unsafe/ops))
to drop in unsafe versions of the library. Alternately, when encountering crashes with code that uses unsafe fixnum operations, use the racket/fixnum library to help debug the problems.
4.2.4.1 Fixnum Arithmetic
procedure
a : fixnum?
procedure
a : fixnum? b : fixnum?
procedure
a : fixnum?
procedure
(fxquotient a b) → fixnum?
a : fixnum? b : fixnum?
procedure
(fxremainder a b) → fixnum?
a : fixnum? b : fixnum?
procedure
a : fixnum? b : fixnum?
procedure
a : fixnum?
Changed in version 7.0.0.13 of package base: Allow zero or more arguments for fx+ and fx* and one or more arguments for fx-.
procedure
a : fixnum?
procedure
a : fixnum?
procedure
a : fixnum?
procedure
a : fixnum?
procedure
a : fixnum? b : fixnum?
procedure
a : fixnum? b : fixnum?
Changed in version 7.0.0.13 of package base: Allow any number of arguments for fxand, fxior, and fxxor.
procedure
a : fixnum? b : fixnum?
procedure
a : fixnum? b : fixnum?
procedure
a : fixnum? b : fixnum?
procedure
a : fixnum? b : fixnum?
procedure
a : fixnum? b : fixnum?
procedure
a : fixnum? b : fixnum?
procedure
a : fixnum? b : fixnum?
Changed in version 7.0.0.13 of package base: Allow one argument, in addition to allowing two or more.
procedure
v : any/c
Added in version 7.3.0.11 of package base.
4.2.4.2 Fixnum Vectors
A fxvector is like a vector, but it holds only fixnums. The only advantage of a fxvector over a vector is that a shared version can be created with functions like shared-fxvector.
Two fxvectors are equal? if they have the same length, and if the values in corresponding slots of the fxvectors are equal?.
A printed fxvector starts with #fx(, optionally with a number between the #fx and (. See Reading Vectors for information on reading fxvectors and Printing Vectors for information on printing fxvectors.
> (fxvector 2 3 4 5) (fxvector 2 3 4 5)
procedure
(make-fxvector size [x]) → fxvector?
size : exact-nonnegative-integer? x : fixnum? = 0
> (make-fxvector 4 3) (fxvector 3 3 3 3)
procedure
vec : fxvector?
procedure
(fxvector-ref vec pos) → fixnum?
vec : fxvector? pos : exact-nonnegative-integer?
procedure
(fxvector-set! vec pos x) → fixnum?
vec : fxvector? pos : exact-nonnegative-integer? x : fixnum?
procedure
(fxvector-copy vec [start end]) → fxvector?
vec : fxvector? start : exact-nonnegative-integer? = 0 end : exact-nonnegative-integer? = (vector-length v)
procedure
(in-fxvector vec [start stop step]) → sequence?
vec : fxvector? start : exact-nonnegative-integer? = 0 stop : (or/c exact-integer? #f) = #f step : (and/c exact-integer? (not/c zero?)) = 1
The optional arguments start, stop, and step are as in in-vector.
An in-fxvector application can provide better performance for fxvector iteration when it appears directly in a for clause.
syntax
(for/fxvector maybe-length (for-clause ...) body ...)
syntax
(for*/fxvector maybe-length (for-clause ...) body ...)
maybe-length =
| #:length length-expr | #:length length-expr #:fill fill-expr
length-expr : exact-nonnegative-integer?
fill-expr : fixnum?
procedure
(shared-fxvector x ...) → fxvector?
x : fixnum?
> (shared-fxvector 2 3 4 5) (fxvector 2 3 4 5)
procedure
(make-shared-fxvector size [x]) → fxvector?
size : exact-nonnegative-integer? x : fixnum? = 0
> (make-shared-fxvector 4 3) (fxvector 3 3 3 3)