► |  | Reference: Racket

1 | Language Model
2 | Syntactic Forms
3 | Datatypes
4 | Structures
5 | Classes and Objects
6 | Units
7 | Contracts
8 | Pattern Matching
9 | Control Flow
10 | Concurrency
11 | Macros
12 | Input and Output
13 | Reflection and Security
14 | Operating System
15 | Memory Management
16 | Unsafe Operations
17 | Running Racket
| Bibliography
| Index

► | 3 | Datatypes

3.1 | Booleans and Equality
3.2 | Numbers
3.3 | Strings
3.4 | Byte Strings
3.5 | Characters
3.6 | Symbols
3.7 | Regular Expressions
3.8 | Keywords
3.9 | Pairs and Lists
3.10 | Mutable Pairs and Lists
3.11 | Vectors
3.12 | Boxes
3.13 | Hash Tables
3.14 | Sequences
3.15 | Dictionaries
3.16 | Sets
3.17 | Procedures
3.18 | Void and Undefined

▼ | 3.2 | Numbers

3.2.1 | Number Types
3.2.2 | Generic Numerics
3.2.3 | Flonums
3.2.4 | Fixnums

► | 3.2.4 | Fixnums

3.2.4.1 | Fixnum Arithmetic
3.2.4.2 | Fixnum Vectors

On this page:

3.2.4.1`` Fixnum Arithmetic
fx+
fx-
fx*
fxquotient
fxremainder
fxmodulo
fxabs
fxand
fxior
fxxor
fxnot
fxlshift
fxrshift
fx=
fx<
fx>
fx<=
fx>=
fxmin
fxmax
fx->fl
fl->fx
3.2.4.2`` Fixnum Vectors
fxvector?
fxvector
make-fxvector
fxvector-length
fxvector-ref
fxvector-set!
fxvector-copy
in-fxvector
for/ fxvector
for*/ fxvector
shared-fxvector
make-shared-fxvector

top ← prev up next →

##### 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

( fx+ a b) → fixnum?
a : fixnum?
b : fixnum?

( fx- a b) → fixnum?
a : fixnum?
b : fixnum?

( fx* a b) → fixnum?
a : fixnum?
b : fixnum?

( fxquotient a b) → fixnum?
a : fixnum?
b : fixnum?

( fxremainder a b) → fixnum?
a : fixnum?
b : fixnum?

( fxmodulo a b) → fixnum?
a : fixnum?
b : fixnum?

( fxabs a) → fixnum?
a : fixnum?

Safe versions of unsafe-fx+, unsafe-fx-, unsafe-fx*, unsafe-fxquotient, unsafe-fxremainder, unsafe-fxmodulo, and unsafe-fxabs. The exn:fail:contract:non-fixnum-result exception is raised if the arithmetic result would not be a fixnum.

( fxand a b) → fixnum?
a : fixnum?
b : fixnum?

( fxior a b) → fixnum?
a : fixnum?
b : fixnum?

( fxxor a b) → fixnum?
a : fixnum?
b : fixnum?

( fxnot a) → fixnum?
a : fixnum?

( fxlshift a b) → fixnum?
a : fixnum?
b : fixnum?

( fxrshift a b) → fixnum?
a : fixnum?
b : fixnum?

Safe versions of unsafe-fxand, unsafe-fxior, unsafe-fxxor, unsafe-fxnot, unsafe-fxlshift, and unsafe-fxrshift. The exn:fail:contract:non-fixnum-result exception is raised if the arithmetic result would not be a fixnum.

( fx= a b) → boolean?
a : fixnum?
b : fixnum?

( fx< a b) → boolean?
a : fixnum?
b : fixnum?

( fx> a b) → boolean?
a : fixnum?
b : fixnum?

( fx<= a b) → boolean?
a : fixnum?
b : fixnum?

( fx>= a b) → boolean?
a : fixnum?
b : fixnum?

( fxmin a b) → fixnum?
a : fixnum?
b : fixnum?

( fxmax a b) → fixnum?
a : fixnum?
b : fixnum?

Safe versions of unsafe-fx=, unsafe-fx<, unsafe-fx>, unsafe-fx<=, unsafe-fx>=, unsafe-fxmin, and unsafe-fxmax.

( fx->fl a) → flonum?
a : fixnum?

( fl->fx a) → fixnum?
a : flonum?

Safe versions of unsafe-fx->fl and unsafe-fl->fx.

##### 3.2.4.2`` Fixnum Vectors

A fxvector is like a vector, but it holds only fixnums. The only advantage of an 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?.

( fxvector? v) → boolean?
v : any/c

Returns #t if v is a fxvector, #f otherwise.

( fxvector x ...) → fxvector?
x : fixnum?

Creates a fxvector containing the given fixnums.

Example:
> ( fxvector 2 3 4 5)
#<fxvector>

( make-fxvector size [x]) → fxvector?
size : exact-nonnegative-integer?
x : fixnum? = 0

Creates a fxvector with size elements, where every slot in the fxvector is filled with x.

Example:
> ( make-fxvector 4 3)
#<fxvector>

( fxvector-length vec) → exact-nonnegative-integer?
vec : fxvector?

Returns the length of vec (i.e., the number of slots in the fxvector).

( fxvector-ref vec pos) → fixnum?
vec : fxvector?
pos : exact-nonnegative-integer?

Returns the fixnum in slot pos of vec. The first slot is position 0, and the last slot is one less than ( fxvector-length vec).

( fxvector-set! vec pos x) → fixnum?
vec : fxvector?
pos : exact-nonnegative-integer?
x : fixnum?

Sets the fixnum in slot pos of vec. The first slot is position 0, and the last slot is one less than ( fxvector-length vec).

( fxvector-copy vec [start end]) → fxvector?
vec : fxvector?
start : exact-nonnegative-integer? = 0
end : exact-nonnegative-integer? = ( vector-length v)

Creates a fresh fxvector of size ( - end start), with all of the elements of vec from start (inclusive) to end (exclusive).

( in-fxvector v) → sequence?
v : fxvector?

Produces a sequence that gives the elements of v in order. Inside a for form, this can be optimized to step through the elements of v efficiently as in in-list, in-vector, etc.

( for/fxvector (for-clause ...) body ...)
( for/fxvector #:length length-expr (for-clause ...) body ...)

( for*/fxvector (for-clause ...) body ...)
( for*/fxvector #:length length-expr (for-clause ...) body ...)

Like for/vector or for*/vector, but for fxvectors.

( shared-fxvector x ...) → fxvector?
x : fixnum?

Creates a fxvector containing the given fixnums. When places are enabled, the new fxvector is allocated in the shared memory space.

Example:
> ( shared-fxvector 2 3 4 5)
#<fxvector>

( make-shared-fxvector size [x]) → fxvector?
size : exact-nonnegative-integer?
x : fixnum? = 0

Creates a fxvector with size elements, where every slot in the fxvector is filled with x. When places are enabled, the new fxvector is allocated in the shared memory space.

Example:
> ( make-shared-fxvector 4 3)
#<fxvector>

top ← prev up next →