3.2.3 Flonums
(require racket/flonum) |
The racket/flonum library provides operations like fl+ that consume and produce only flonums. Flonum-specific operations can provide better performance when used consistently, and they are as safe as generic operations like +.
See also Fixnum and Flonum Optimizations in The Racket Guide.
3.2.3.1 Flonum Arithmetic
procedure
a : flonum? b : flonum?
procedure
a : flonum? b : flonum?
procedure
a : flonum? b : flonum?
procedure
a : flonum? b : flonum?
procedure
a : flonum?
procedure
a : flonum? b : flonum?
procedure
a : flonum? b : flonum?
procedure
a : flonum? b : flonum?
procedure
a : flonum? b : flonum?
procedure
a : flonum? b : flonum?
procedure
a : flonum? b : flonum?
procedure
a : flonum? b : flonum?
procedure
a : flonum?
procedure
a : flonum?
procedure
a : flonum?
procedure
(fltruncate a) → flonum?
a : flonum?
procedure
a : flonum?
procedure
a : flonum?
procedure
a : flonum?
procedure
a : flonum?
procedure
a : flonum?
procedure
a : flonum?
procedure
a : flonum?
procedure
a : flonum?
procedure
a : flonum?
procedure
a : exact-integer?
procedure
a : flonum?
procedure
(make-flrectangular a b)
→ (and/c complex? inexact? (not/c real?)) a : flonum? b : flonum?
procedure
(flreal-part a) → flonum?
a : (and/c complex? inexact? (not/c real?))
procedure
(flimag-part a) → flonum?
a : (and/c complex? inexact? (not/c real?))
3.2.3.2 Flonum Vectors
A flvector is like a vector, but it holds only inexact real numbers. This representation can be more compact, and unsafe operations on flvectors (see racket/unsafe/ops) can execute more efficiently than unsafe operations on vectors of inexact reals.
An f64vector as provided by ffi/vector stores the same kinds of values as a flvector, but with extra indirections that make f64vectors more convenient for working with foreign libraries. The lack of indirections makes unsafe flvector access more efficient.
Two flvectors are equal? if they have the same length, and if the values in corresponding slots of the flvectors are equal?.
Example: | ||
|
procedure
(make-flvector size [x]) → flvector?
size : exact-nonnegative-integer? x : flonum? = 0.0
Example: | ||
|
procedure
vec : flvector?
procedure
(flvector-ref vec pos) → flonum?
vec : flvector? pos : exact-nonnegative-integer?
procedure
(flvector-set! vec pos x) → flonum?
vec : flvector? pos : exact-nonnegative-integer? x : flonum?
procedure
(flvector-copy vec [start end]) → flvector?
vec : flvector? start : exact-nonnegative-integer? = 0 end : exact-nonnegative-integer? = (vector-length v)
procedure
(in-flvector vec [start stop step]) → sequence?
vec : flvector? 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.
A in-flvector application can provide better performance for flvector iteration when it appears directly in a for clause.
syntax
(for/flvector maybe-length (for-clause ...) body ...)
syntax
(for*/flvector maybe-length (for-clause ...) body ...)
maybe-length =
| #:length length-expr | #:length length-expr #:fill fill-expr
length-expr : exact-nonnegative-integer?
fill-expr : flonum?
procedure
(shared-flvector x ...) → flvector?
x : flonum?
Example: | ||
|
procedure
(make-shared-flvector size [x]) → flvector?
size : exact-nonnegative-integer? x : flonum? = 0.0
Example: | ||
|