]> gitweb.factorcode.org Git - factor.git/blob - basis/float-arrays/float-arrays-docs.factor
Create basis vocab root
[factor.git] / basis / float-arrays / float-arrays-docs.factor
1 USING: arrays bit-arrays vectors strings sbufs
2 kernel help.markup help.syntax math ;
3 IN: float-arrays
4
5 ARTICLE: "float-arrays" "Float arrays"
6 "Float arrays are fixed-size mutable sequences (" { $link "sequence-protocol" } ") whose elements are instances of " { $link float } ". Elements are unboxed, hence the memory usage is lower than an equivalent " { $link array } " of floats."
7 $nl
8 "Float array words are in the " { $vocab-link "float-arrays" } " vocabulary."
9 $nl
10 "Float arrays play a special role in the C library interface; they can be used to pass binary data back and forth between Factor and C. See " { $link "c-byte-arrays" } "."
11 $nl
12 "Float arrays form a class of objects."
13 { $subsection float-array }
14 { $subsection float-array? }
15 "There are several ways to construct float arrays."
16 { $subsection >float-array }
17 { $subsection <float-array> }
18 "Creating a float array from several elements on the stack:"
19 { $subsection 1float-array }
20 { $subsection 2float-array }
21 { $subsection 3float-array }
22 { $subsection 4float-array }
23 "Float array literal syntax:"
24 { $subsection POSTPONE: F{ } ;
25
26 ABOUT: "float-arrays"
27
28 HELP: F{
29 { $syntax "F{ elements... }" }
30 { $values { "elements" "a list of real numbers" } }
31 { $description "Marks the beginning of a literal float array. Literal float arrays are terminated by " { $link POSTPONE: } } "." } 
32 { $examples { $code "F{ 1.0 2.0 3.0 }" } } ;
33
34 HELP: float-array
35 { $description "The class of float arrays." } ;
36
37 HELP: <float-array> ( n -- float-array )
38 { $values { "n" "a non-negative integer" } { "float-array" "a new float array" } }
39 { $description "Creates a new float array holding " { $snippet "n" } " floats with all elements initially set to " { $snippet "0.0" } "." } ;
40
41 HELP: >float-array
42 { $values { "seq" "a sequence" } { "float-array" float-array } }
43 { $description "Outputs a freshly-allocated float array whose elements have the same floating-point values as a given sequence." }
44 { $errors "Throws an error if the sequence contains elements other than real numbers." } ;
45
46 HELP: 1float-array
47 { $values { "x" object } { "array" float-array } }
48 { $description "Create a new float array with one element." } ;
49
50 { 1array 2array 3array 4array } related-words
51
52 HELP: 2float-array
53 { $values { "x" object } { "y" object } { "array" float-array } }
54 { $description "Create a new float array with two elements, with " { $snippet "x" } " appearing first." } ;
55
56 HELP: 3float-array
57 { $values { "x" object } { "y" object } { "z" object } { "array" float-array } }
58 { $description "Create a new float array with three elements, with " { $snippet "x" } " appearing first." } ;
59
60 HELP: 4float-array
61 { $values { "w" object } { "x" object } { "y" object } { "z" object } { "array" float-array } }
62 { $description "Create a new float array with four elements, with " { $snippet "w" } " appearing first." } ;