basic/doc/chapter_3.rs
1/*!
2# Functions
3
4Functions convert various inputs to an output value. Most functions convert
5a value to a value but some get their input from the operating system.
6For example, `TIME$` gets the local system time. You might be wondering why
7`TIME$` is a function and not a variable. You can use `TIME$()` if you prefer.
8*/
9
10pub mod ABS {
11 /*!
12 ## `ABS(X)` Returns the absolute value of X.
13 ```text
14 PRINT ABS(-0.123)
15 0.123
16 ```
17 */
18}
19
20pub mod ASC {
21 /*!
22 ## `ASC(X$)` Returns the unicode value of the first character of X.
23 ```text
24 PRINT ASC("A")
25 65
26 ```
27 */
28}
29
30pub mod ATN {
31 /*!
32 ## `ATN(X)` Returns the arctangent of X.
33 ```text
34 PRINT ATN(3)
35 1.2490457
36 ```
37 */
38}
39
40pub mod CDBL {
41 /*!
42 ## `CDBL(X)` Returns X as a Double.
43 ```text
44 PRINT 1/CDBL(3)
45 0.3333333333333333
46 ```
47 */
48}
49
50pub mod CHR {
51 /*!
52 ## `CHR$(X)` Returns a character of ASCII X.
53 ```text
54 PRINT CHR$(65)
55 A
56 ```
57 */
58}
59
60pub mod CINT {
61 /*!
62 ## `CINT(X)` Returns X as an Integer. Overflow error may occur.
63 ```text
64 PRINT CINT(-9.9)
65 -10
66 ```
67 */
68}
69
70pub mod COS {
71 /*!
72 ## `COS(X)` Returns the cosine of X in radians.
73 ```text
74 PRINT COS(0.123)
75 0.99244505
76 ```
77 */
78}
79
80pub mod CSNG {
81 /*!
82 ## `CSNG(X)` Returns X as a Single.
83 ```text
84 PRINT 1/CSNG(3#)
85 0.33333334
86 ```
87 */
88}
89
90pub mod DATE {
91 /*!
92 ## `DATE$` Returns the system date.
93 ```text
94 PRINT DATE$
95 12-31-2000
96 ```
97 */
98}
99
100pub mod EXP {
101 /*!
102 ## `EXP(X)` Returns e to the power of X.
103 ```text
104 PRINT EXP(1)
105 2.7182817
106 ```
107 */
108}
109
110pub mod FIX {
111 /*!
112 ## `FIX(X)` Returns the truncated integer value of X.
113 See `INT` for a flooring function.
114 ```text
115 PRINT FIX( 9.9) FIX(-9.9)
116 9 9
117 ```
118 */
119}
120
121pub mod HEX {
122 /*!
123 ## `HEX$(X)` Returns hexadecimal string of integer X.
124 ```text
125 PRINT HEX$(-1)
126 FFFF
127 ```
128 */
129}
130
131pub mod INKEY {
132 /*!
133 ## `INKEY$` Returns a single key press, empty string if none.
134 ```text
135 I$="":WHILE LEN(I$)=0:I$=INKEY$:WEND:PRINT I$
136 ```
137 */
138}
139
140pub mod INSTR {
141 /*!
142 ## `INSTR([I],X$,Y$)` Returns position of Y$ in X$.
143 Optionally, start searching at index I.
144 Returns 0 if not found. Returns I or 1 if Y$ = "".
145 ```text
146 PRINT INSTR("abcdeb","b")
147 2
148 PRINT INSTR(5,"abcdeb","b")
149 6
150 ```
151 */
152}
153
154pub mod INT {
155 /*!
156 ## `INT(X)` Returns the largest integer <= X.
157 See `FIX` for a truncating function.
158 ```text
159 PRINT INT(9.9) INT(-9.9)
160 9 -10
161 ```
162 */
163}
164
165pub mod LEFT {
166 /*!
167 ## `LEFT$(A$,X)` Returns the leftmost X characters of A$.
168 ```text
169 PRINT LEFT$("HUNT THE WUMPUS", 4)
170 HUNT
171 ```
172 */
173}
174
175pub mod LEN {
176 /*!
177 ## `LEN(X$)` Returns the number of characters in X$.
178 ```text
179 PRINT LEN("TO")
180 2
181 ```
182 */
183}
184
185pub mod LOG {
186 /*!
187 ## `LOG(X)` Returns the natural logarithm of X.
188 ```text
189 PRINT LOG(8/37)
190 -1.5314764
191 ```
192 */
193}
194
195pub mod MID {
196 /*!
197 ## `MID$(A$,X,[Y])` Returns a portion of A$.
198 The returned string will begin with the character in position X.
199 If Y is present it will limit the length, otherwise everything
200 until the end of the string is returned.
201 ```text
202 PRINT MID$("HUNT THE WUMPUS", 6, 3)
203 THE
204 PRINT MID$("HUNT THE WUMPUS", 6)
205 THE WUMPUS
206 ```
207 */
208}
209
210pub mod OCT {
211 /*!
212 ## `OCT$(X)` Returns octal string of integer X.
213 ```text
214 PRINT OCT$(-1)
215 177777
216 ```
217 */
218}
219
220pub mod RIGHT {
221 /*!
222 ## `RIGHT$(A$,X)` Returns the rightmost X characters of A$.
223 ```text
224 PRINT RIGHT$("HUNT THE WUMPUS", 6)
225 WUMPUS
226 ```
227 */
228}
229
230pub mod POS {
231 /*!
232 ## `POS(X)` Returns the horizontal cursor position of the terminal.
233 `X` is optional and ignored. First position is 0.
234 ```text
235 PRINT " ";POS()
236 5
237 ```
238 */
239}
240
241pub mod RND {
242 /*!
243 ## `RND(X)` Returns a pseudo-random number.
244 Wichman-Hill Random Number Generator.
245 Returns a random Single between 0 and 1 when X is missing or > 0.
246 When X is 0, return the previous random number.
247 When X < 0 the random number generator is seeded with X.
248 The `CLEAR`, `NEW` and `RUN` statements reseed the generator with entropy.
249 ```text
250 PRINT RND()
251 0.6923401
252 ```
253 */
254}
255
256pub mod SGN {
257 /*!
258 ## `SGN(X)` Returns the sign of X.
259 Returns -1 if X is negative, 1 if positive, and 0 if zero.
260 ```text
261 PRINT SGN(+1)
262 1
263 ```
264 */
265}
266
267pub mod SIN {
268 /*!
269 ## `SIN(X)` Returns the sine of X in radians.
270 ```text
271 PRINT SIN(0.123)
272 0.1226901
273 ```
274 */
275}
276
277pub mod SPC {
278 /*!
279 ## `SPC(X)` Returns a string of X spaces.
280 ```text
281 PRINT "<"SPC(5)">"
282 < >
283 ```
284 */
285}
286
287pub mod SQR {
288 /*!
289 ## `SQR(X)` Returns the square root of X.
290 ```text
291 PRINT SQR(5)
292 2.236068
293 ```
294 */
295}
296
297pub mod STR {
298 /*!
299 ## `STR$(X)` Returns the number X as a string.
300 ```text
301 PRINT STR$(-3.14) + "!"
302 -3.14!
303 ```
304 */
305}
306
307pub mod STRING {
308 /*!
309 ## `STRING$(X, <Y|Y$>)` Returns X copies of Y as a string.
310 You can specify Y as an integer or a string. Only the first
311 character of a string is used.
312 ```text
313 PRINT STRING$(5,45)"KAPOW"STRING$(5,"-")
314 -----KAPOW-----
315 ```
316 */
317}
318
319pub mod TAB {
320 /*!
321 ## `TAB(X)` Returns a string of spaces.
322 Used in a `PRINT` statement, moves to the requested column.
323 Does nothing if already past the requested column.
324 If X is negative, moves to the start of next -X wide zone.
325 ```text
326 PRINT 1.99 TAB(20) "furlongs per year"
327 1.99 furlongs per year
328 ```
329 */
330}
331
332pub mod TAN {
333 /*!
334 ## `TAN(X)` Returns the tangent of X in radians.
335 ```text
336 PRINT TAN(5/13)
337 0.40477434
338 ```
339 */
340}
341
342pub mod TIME {
343 /*!
344 ## `TIME$` Returns the system time.
345 ```text
346 PRINT TIME$
347 23:59:59
348 ```
349 */
350}
351
352pub mod VAL {
353 /*!
354 ## `VAL(X$)` Returns a number parsed from string X$.
355 ```text
356 PRINT VAL("1E-2")
357 0.01
358 ```
359 */
360}