3.2.4 Fixnums
(require racket/fixnum) |
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) (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.
3.2.4.1 Fixnum Arithmetic
procedure
a : fixnum? b : fixnum?
procedure
a : fixnum? b : fixnum?
procedure
a : fixnum? b : 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?
procedure
a : fixnum? b : fixnum?
procedure
a : fixnum? b : fixnum?
procedure
a : fixnum? b : fixnum?
procedure
a : 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?
procedure
a : fixnum? b : fixnum?
procedure
a : fixnum? b : fixnum?
procedure
a : fixnum? b : fixnum?
3.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?.
Example: | ||
|
procedure
(make-fxvector size [x]) → fxvector?
size : exact-nonnegative-integer? x : fixnum? = 0
Example: | ||
|
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 (for-clause ...) body ...)
(for/fxvector #:length length-expr (for-clause ...) body ...)
syntax
(for*/fxvector (for-clause ...) body ...)
(for*/fxvector #:length length-expr (for-clause ...) body ...)
procedure
(shared-fxvector x ...) → fxvector?
x : fixnum?
Example: | ||
|
procedure
(make-shared-fxvector size [x]) → fxvector?
size : exact-nonnegative-integer? x : fixnum? = 0
Example: | ||
|