4.3.3 Flonums
(require racket/flonum) | package: base |
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.
4.3.3.1 Flonum Arithmetic
procedure
a : flonum?
procedure
a : flonum? b : flonum?
procedure
a : flonum?
procedure
a : flonum? b : flonum?
procedure
a : flonum?
Changed in version 7.0.0.13 of package base: Allow zero or more arguments for fl+ and fl* and one or more arguments for fl- and fl/.
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?
Changed in version 7.0.0.13 of package base: Allow one argument, in addition to allowing two or more.
procedure
a : flonum?
procedure
a : flonum?
procedure
a : flonum?
procedure
(fltruncate a) → flonum?
a : flonum?
Using flsingle on the arguments and results of fl+,
fl-, fl*, fl/, and flsqrt—
Added in version 7.8.0.7 of package base.
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? (lambda (c) (flonum? (real-part c))) (lambda (c) (flonum? (imag-part c)))) a : flonum? b : flonum?
procedure
(flreal-part a) → flonum?
a :
(and/c complex? (lambda (c) (flonum? (real-part c))) (lambda (c) (flonum? (imag-part c))))
procedure
(flimag-part a) → flonum?
a :
(and/c complex? (lambda (c) (flonum? (real-part c))) (lambda (c) (flonum? (imag-part c))))
4.3.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?.
A printed flvector starts with #fl(, optionally with a number between the #fl and (. See Reading Vectors for information on reading flvectors and Printing Vectors for information on printing flvectors.
> (flvector 2.0 3.0 4.0 5.0) (flvector 2.0 3.0 4.0 5.0)
procedure
(make-flvector size [x]) → flvector?
size : exact-nonnegative-integer? x : flonum? = 0.0
> (make-flvector 4 3.0) (flvector 3.0 3.0 3.0 3.0)
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?
> (shared-flvector 2.0 3.0 4.0 5.0) (flvector 2.0 3.0 4.0 5.0)
procedure
(make-shared-flvector size [x]) → flvector?
size : exact-nonnegative-integer? x : flonum? = 0.0
> (make-shared-flvector 4 3.0) (flvector 3.0 3.0 3.0 3.0)