4.3.3 Flonums

4.3 Numbers
4.3.1 Number Types
4.3.3 Flonums
4.3.4 Fixnums
4.3.5 Extflonums
4.3.3 Flonums
On this page:
fl+
fl-
fl*
fl/
fl=
fl<
fl>
top
up

4.3.3FlonumsπŸ”— i

(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.1Flonum ArithmeticπŸ”— i

procedure

( fl+ a...)flonum?

procedure

( fl- ab...)flonum?

procedure

( fl* a...)flonum?

procedure

( fl/ ab...)flonum?

procedure

( flabs a)flonum?

Like + , - , * , / , and abs , but constrained to consume flonums. The result is always 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

( fl= ab...)boolean?

procedure

( fl< ab...)boolean?

procedure

( fl> ab...)boolean?

procedure

( fl<= ab...)boolean?

procedure

( fl>= ab...)boolean?

procedure

( flmin ab...)flonum?

procedure

( flmax ab...)flonum?

Like = , < , > , <= , >= , min , and max , but constrained to consume flonums.

Changed in version 7.0.0.13 of package base: Allow one argument, in addition to allowing two or more.

procedure

( flround a)flonum?

procedure

( flfloor a)flonum?

procedure

( flceiling a)flonum?

procedure

( fltruncate a)flonum?

Like round , floor , ceiling , and truncate , but constrained to consume flonums.

procedure

( flsingle a)flonum?

Returns a value like a, but potentially discards precision and range so that the result can be represented as a single-precision IEEE floating-point number (even if single-flonums are not supported).

Using flsingle on the arguments and results of fl+ , fl- , fl* , fl/ , and flsqrt —that is, performing double-precision operations on values representable in single precision and then rounding the result to single precision—is always the same as performing the corresponding single-precision operation [Roux14]. (For other operations, the IEEE floating-point specification does not make enough guarantees to say more about the interaction with flsingle .)

Added in version 7.8.0.7 of package base.

procedure

( flbit-field astartend)exact-nonnegative-integer?

start:(integer-in 064)
end:(integer-in 064)
Extracts a range of bits from the 64-bit IEEE representation of a, returning the non-negative integer that has the same bits set in its (semi-infinite) two’s complement representation.

Examples:
> (flbit-field -0.06364)

1

> (format "~x"(flbit-field 3.141579e+1321648))

"b43544f2"

Added in version 8.15.0.3 of package base.

procedure

( flsin a)flonum?

procedure

( flcos a)flonum?

procedure

( fltan a)flonum?

procedure

( flasin a)flonum?

procedure

( flacos a)flonum?

procedure

( flatan a)flonum?

procedure

( fllog a)flonum?

procedure

( flexp a)flonum?

procedure

( flsqrt a)flonum?

Like sin , cos , tan , asin , acos , atan , log , exp , and sqrt , but constrained to consume and produce flonums. The result is +nan.0 when a number outside the range -1.0 to 1.0 is given to flasin or flacos , or when a negative number is given to fllog or flsqrt .

procedure

( flexpt ab)flonum?

Like expt , but constrained to consume and produce flonums.

Due to the result constraint, the results compared to expt differ in the following cases: These special cases correspond to pow in C99 [C99].
  • (flexpt -1.0+inf.0)1.0

  • (flexpt a+inf.0) where a is negative — (expt (abs a)+inf.0)

  • (flexpt a-inf.0) where a is negative — (expt (abs a)-inf.0)

  • (expt -inf.0b) where b is a non-integer:
    • b is negative — 0.0

    • b is positive — +inf.0

  • (flexpt ab) where a is negative and b is not an integer — +nan.0

procedure

( ->fl a)flonum?

Like exact->inexact , but constrained to consume exact integers, so the result is always a flonum.

Like inexact->exact , but constrained to consume an integer flonum, so the result is always an exact integer.

procedure

( flreal-part a)flonum?

procedure

( flimag-part a)flonum?

Like make-rectangular , real-part , and imag-part , but both parts of the complex number must be inexact.

procedure

( flrandom rand-gen)(and flonum? (>/c 0)(</c 1))

Equivalent to (random rand-gen).

4.3.3.2Flonum VectorsπŸ”— i

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 read ing flvectors and Printing Vectors for information on print ing flvectors.

procedure

( flvector? v)boolean?

v:any/c
Returns #t if v is a flvector, #f otherwise.

procedure

( flvector x...)flvector?

Creates a flvector containing the given inexact real numbers.

Example:
> (flvector 2.03.04.05.0)

(flvector 2.0 3.0 4.0 5.0)

procedure

( make-flvector size[x])flvector?

x:flonum? =0.0
Creates a flvector with size elements, where every slot in the flvector is filled with x.

Example:
> (make-flvector 43.0)

(flvector 3.0 3.0 3.0 3.0)

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

Returns the inexact real number in slot pos of vec. The first slot is position 0, and the last slot is one less than (flvector-length vec).

Sets the inexact real number in slot pos of vec. The first slot is position 0, and the last slot is one less than (flvector-length vec).

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

procedure

( in-flvector vec[startstopstep])sequence?

vec:flvector?
stop:(or/c exact-integer? #f)=#f
Returns a sequence equivalent to vec when no optional arguments are supplied.

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 =
| #:lengthlength-expr
| #:lengthlength-expr#:fillfill-expr
fill-expr : flonum?
Like for/vector or for*/vector , but for flvectors. The default fill-expr produces 0.0.

procedure

( shared-flvector x...)flvector?

Creates a flvector containing the given inexact real numbers. For communication among places, the new flvector is allocated in the shared memory space.

Example:
> (shared-flvector 2.03.04.05.0)

(flvector 2.0 3.0 4.0 5.0)

Creates a flvector with size elements, where every slot in the flvector is filled with x. For communication among places, the new flvector is allocated in the shared memory space.

Example:

(flvector 3.0 3.0 3.0 3.0)

top
up

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /