]> gitweb.factorcode.org Git - factor.git/blob - core/math/parser/parser-docs.factor
Fix conflict
[factor.git] / core / math / parser / parser-docs.factor
1 USING: help.markup help.syntax math math.parser.private prettyprint
2 namespaces make strings ;
3 IN: math.parser
4
5 ARTICLE: "number-strings" "Converting between numbers and strings"
6 "These words only convert between real numbers and strings. Complex numbers are constructed by the parser (" { $link "parser" } ") and printed by the prettyprinter (" { $link "prettyprint" } ")."
7 $nl
8 "Integers can be converted to and from arbitrary bases. Floating point numbers can only be converted to and from base 10 and 16."
9 $nl
10 "Converting numbers to strings:"
11 { $subsections
12     number>string
13     >bin
14     >oct
15     >hex
16     >base
17 }
18 "Converting strings to numbers:"
19 { $subsections
20     string>number
21     bin>
22     oct>
23     hex>
24     base>
25 }
26 "You can also input literal numbers in a different base (" { $link "syntax-integers" } ")."
27 { $see-also "prettyprint-numbers" } ;
28
29 ABOUT: "number-strings"
30
31 HELP: digits>integer
32 { $values { "seq" "a sequence of integers" } { "radix" "an integer between 2 and 36" } { "n/f" { $maybe integer } } }
33 { $description "Converts a sequence of digits (with most significant digit first) into an integer." }
34 { $notes "This is one of the factors of " { $link string>number } "." } ;
35
36 HELP: >digit
37 { $values { "n" "an integer between 0 and 35" } { "ch" "a character" } }
38 { $description "Outputs a character representation of a digit." }
39 { $notes "This is one of the factors of " { $link number>string } "." } ;
40
41 HELP: digit>
42 { $values { "ch" "a character" } { "n" integer } }
43 { $description "Converts a character representation of a digit to an integer." }
44 { $notes "This is one of the factors of " { $link string>number } "." } ;
45
46 HELP: base>
47 { $values { "str" string } { "radix" "an integer between 2 and 36" } { "n/f" "a real number or " { $link f } } }
48 { $description "Creates a real number from a string representation with the given radix. The radix is ignored for floating point literals; they are always taken to be in base 10."
49 $nl
50 "Outputs " { $link f } " if the string does not represent a number." } ;
51
52 { >base base> } related-words
53
54 HELP: string>number
55 { $values { "str" string } { "n/f" "a real number or " { $link f } } }
56 { $description "Creates a real number from a string representation of a number in base 10."
57 $nl
58 "Outputs " { $link f } " if the string does not represent a number." } ;
59
60 { string>number number>string } related-words
61
62 HELP: bin>
63 { $values { "str" string } { "n/f" "a real number or " { $link f } } }
64 { $description "Creates a real number from a string representation of a number in base 2."
65 $nl
66 "Outputs " { $link f } " if the string does not represent a number." } ;
67
68 { >bin POSTPONE: BIN: bin> .b } related-words
69
70 HELP: oct>
71 { $values { "str" string } { "n/f" "a real number or " { $link f } } }
72 { $description "Creates a real number from a string representation of a number in base 8."
73 $nl
74 "Outputs " { $link f } " if the string does not represent a number." } ;
75
76 { >oct POSTPONE: OCT: oct> .o } related-words
77
78 HELP: hex>
79 { $values { "str" string } { "n/f" "a real number or " { $link f } } }
80 { $description "Creates a real number from a string representation of a number in base 16."
81 $nl
82 "Outputs " { $link f } " if the string does not represent a number." } ;
83
84 { >hex POSTPONE: HEX: hex> .h } related-words
85
86 HELP: >base
87 { $values { "n" real } { "radix" "an integer between 2 and 36" } { "str" string } }
88 { $description "Converts a real number into a string representation using the given radix. If the number is a float, the radix is ignored and the output is always in base 10." } ;
89
90 HELP: >bin
91 { $values { "n" real } { "str" string } }
92 { $description "Outputs a string representation of a number using base 2." } ;
93
94 HELP: >oct
95 { $values { "n" real } { "str" string } }
96 { $description "Outputs a string representation of a number using base 8." } ;
97
98 HELP: >hex
99 { $values { "n" real } { "str" string } }
100 { $description "Outputs a string representation of a number using base 16." }
101 { $examples
102     { $example
103         "USING: math.parser prettyprint ;"
104         "3735928559 >hex ."
105         "\"deadbeef\""
106     }
107     { $example
108         "USING: math.parser prettyprint ;"
109         "-15.5 >hex ."
110         "\"-1.fp3\""
111     }
112 } ;
113
114 HELP: string>float ( str -- n/f )
115 { $values { "str" string } { "n/f" "a real number or " { $link f } } }
116 { $description "Primitive for creating a float from a string representation." }
117 { $notes "The " { $link string>number } " word is more general."
118 $nl
119 "Outputs " { $link f } " if the string does not represent a float." } ;
120
121 HELP: float>string
122 { $values { "n" real } { "str" string } }
123 { $description "Primitive for getting a string representation of a float." }
124 { $notes "The " { $link number>string } " word is more general." } ;
125
126 HELP: number>string
127 { $values { "n" real } { "str" string } }
128 { $description "Converts a real number to a string." }
129 { $notes "Printing complex numbers requires the more general prettyprinter facility (see " { $link "prettyprint" } ")." } ;
130
131 HELP: #
132 { $values { "n" real } }
133 { $description "Appends the string representation of a real number to the end of the sequence being constructed by " { $link make } "." } ;