Skip to main content

rl_lang/docs/entries/stdlib/math/
mod.rs

1use crate::docs::entry::{FnEntry, StdEntry};
2pub static MATH: StdEntry = StdEntry {
3    name: "math",
4    description: "functions for math",
5    functions: FUNCTIONS,
6    since: None,
7    unstable: false,
8};
9
10static FUNCTIONS: &[&FnEntry] = &[
11    &ABS, &ACOS, &ASIN, &ATAN, &ATAN2, &CEIL, &CLAMP, &COS, &DEGREES, &EXP, &FACTORIAL, &FIBONACCI,
12    &FLOOR, &GCD, &HYPOT, &IS_PRIME, &LCM, &LERP, &LOG, &LOG2, &LOG10, &MAP_RANGE, &MAX, &MIN,
13    &MOD, &POW, &RADIANS, &ROUND, &SIGN, &SIN, &SQRT, &TAN,
14];
15
16static ABS: FnEntry = FnEntry {
17    signature: "abs(number)",
18    description: "returns the absolute value of number",
19    example: "get std::math::abs\n\ndec int x = -1\nx.abs() // 1",
20    expected_output: None,
21    returns: "",
22    errors: None,
23    see_also: &[],
24    since: None,
25};
26
27static ACOS: FnEntry = FnEntry {
28    signature: "acos(x)",
29    description: "arc cosine of x in radians",
30    example: "get std::math::acos\n\nacos(1.0) // 0.0",
31    expected_output: None,
32    returns: "",
33    errors: None,
34    see_also: &[],
35    since: None,
36};
37
38static ASIN: FnEntry = FnEntry {
39    signature: "asin(x)",
40    description: "arc sine of x in radians",
41    example: "get std::math::asin\n\nasin(1.0) // 1.5707...",
42    expected_output: None,
43    returns: "",
44    errors: None,
45    see_also: &[],
46    since: None,
47};
48
49static ATAN: FnEntry = FnEntry {
50    signature: "atan(x)",
51    description: "arc tangent of x in radians",
52    example: "get std::math::atan\n\natan(1.0) // 0.7853...",
53    expected_output: None,
54    returns: "",
55    errors: None,
56    see_also: &[],
57    since: None,
58};
59
60static ATAN2: FnEntry = FnEntry {
61    signature: "atan2(a, b)",
62    description: "arc tangent of a/b using signs to determine quadrant",
63    example: "get std::math::atan2\n\natan2(1.0, 1.0) // 0.7853...",
64    expected_output: None,
65    returns: "",
66    errors: None,
67    see_also: &[],
68    since: None,
69};
70
71static CEIL: FnEntry = FnEntry {
72    signature: "ceil(x)",
73    description: "smallest integer greater than or equal to x",
74    example: "get std::math::ceil\n\nceil(2.12) // 3.0",
75    expected_output: None,
76    returns: "",
77    errors: None,
78    see_also: &[],
79    since: None,
80};
81
82static CLAMP: FnEntry = FnEntry {
83    signature: "clamp(x, min, max)",
84    description: "clamps x between min and max, returning min if x < min, max if x > max",
85    example: "get std::math::clamp\n\nclamp(12, 15, 20) // 15",
86    expected_output: None,
87    returns: "",
88    errors: None,
89    see_also: &[],
90    since: None,
91};
92
93static COS: FnEntry = FnEntry {
94    signature: "cos(x)",
95    description: "cosine of x in radians",
96    example: "get std::math::cos\n\ncos(0.0) // 1.0",
97    expected_output: None,
98    returns: "",
99    errors: None,
100    see_also: &[],
101    since: None,
102};
103
104static DEGREES: FnEntry = FnEntry {
105    signature: "degrees(x)",
106    description: "convert radians to degrees",
107    example: "get std::math::degrees\n\ndegrees(3.14159) // 180.0",
108    expected_output: None,
109    returns: "",
110    errors: None,
111    see_also: &[],
112    since: None,
113};
114
115static EXP: FnEntry = FnEntry {
116    signature: "exp(x)",
117    description: "e raised to the power x",
118    example: "get std::math::exp\n\nexp(1.0) // 2.718...",
119    expected_output: None,
120    returns: "",
121    errors: None,
122    see_also: &[],
123    since: None,
124};
125
126static FACTORIAL: FnEntry = FnEntry {
127    signature: "factorial(x)",
128    description: "product of all integers from 1 to x",
129    example: "get std::math::factorial\n\nfactorial(5) // 120",
130    expected_output: None,
131    returns: "",
132    errors: None,
133    see_also: &[],
134    since: None,
135};
136
137static FIBONACCI: FnEntry = FnEntry {
138    signature: "fibonacci(x)",
139    description: "xth fibonacci number",
140    example: "get std::math::fibonacci\n\nfibonacci(7) // 13",
141    expected_output: None,
142    returns: "",
143    errors: None,
144    see_also: &[],
145    since: None,
146};
147
148static FLOOR: FnEntry = FnEntry {
149    signature: "floor(x)",
150    description: "largest integer less than or equal to x",
151    example: "get std::math::floor\n\nfloor(1.23) // 1.0",
152    expected_output: None,
153    returns: "",
154    errors: None,
155    see_also: &[],
156    since: None,
157};
158
159static GCD: FnEntry = FnEntry {
160    signature: "gcd(a, b)",
161    description: "greatest common divisor of a and b",
162    example: "get std::math::gcd\n\ngcd(12, 8) // 4",
163    expected_output: None,
164    returns: "",
165    errors: None,
166    see_also: &[],
167    since: None,
168};
169
170static HYPOT: FnEntry = FnEntry {
171    signature: "hypot(a, b)",
172    description: "length of the hypotenuse given two sides: √(a² + b²)",
173    example: "get std::math::hypot\n\nhypot(3.0, 4.0) // 5.0",
174    expected_output: None,
175    returns: "",
176    errors: None,
177    see_also: &[],
178    since: None,
179};
180
181static IS_PRIME: FnEntry = FnEntry {
182    signature: "is_prime(x)",
183    description: "true if x is a prime number",
184    example: "get std::math::is_prime\n\nis_prime(7) // true",
185    expected_output: None,
186    returns: "",
187    errors: None,
188    see_also: &[],
189    since: None,
190};
191
192static LCM: FnEntry = FnEntry {
193    signature: "lcm(a, b)",
194    description: "least common multiple of a and b",
195    example: "get std::math::lcm\n\nlcm(4, 6) // 12",
196    expected_output: None,
197    returns: "",
198    errors: None,
199    see_also: &[],
200    since: None,
201};
202
203static LERP: FnEntry = FnEntry {
204    signature: "lerp(x, y, t)",
205    description: "linear interpolation between x and y by factor t",
206    example: "get std::math::lerp\n\nlerp(0.0, 10.0, 0.5) // 5.0",
207    expected_output: None,
208    returns: "",
209    errors: None,
210    see_also: &[],
211    since: None,
212};
213
214static LOG: FnEntry = FnEntry {
215    signature: "log(x, base)",
216    description: "logarithm of x in the given base",
217    example: "get std::math::log\n\nlog(100.0, 10.0) // 2.0",
218    expected_output: None,
219    returns: "",
220    errors: None,
221    see_also: &[],
222    since: None,
223};
224
225static LOG2: FnEntry = FnEntry {
226    signature: "log2(x)",
227    description: "base-2 logarithm of x",
228    example: "get std::math::log2\n\nlog2(8.0) // 3.0",
229    expected_output: None,
230    returns: "",
231    errors: None,
232    see_also: &[],
233    since: None,
234};
235
236static LOG10: FnEntry = FnEntry {
237    signature: "log10(x)",
238    description: "base-10 logarithm of x",
239    example: "get std::math::log10\n\nlog10(1000.0) // 3.0",
240    expected_output: None,
241    returns: "",
242    errors: None,
243    see_also: &[],
244    since: None,
245};
246
247static MAP_RANGE: FnEntry = FnEntry {
248    signature: "map_range(x, in_min, in_max, out_min, out_max)",
249    description: "re-map x from one range to another",
250    example: "get std::math::map_range\n\nmap_range(5.0, 0.0, 10.0, 0.0, 100.0) // 50.0",
251    expected_output: None,
252    returns: "",
253    errors: None,
254    see_also: &[],
255    since: None,
256};
257
258static MAX: FnEntry = FnEntry {
259    signature: "max(a, b)",
260    description: "returns the larger of a and b",
261    example: "get std::math::max\n\nmax(4, 6) // 6",
262    expected_output: None,
263    returns: "",
264    errors: None,
265    see_also: &[],
266    since: None,
267};
268
269static MIN: FnEntry = FnEntry {
270    signature: "min(a, b)",
271    description: "returns the smaller of a and b",
272    example: "get std::math::min\n\nmin(4, 6) // 4",
273    expected_output: None,
274    returns: "",
275    errors: None,
276    see_also: &[],
277    since: None,
278};
279
280static MOD: FnEntry = FnEntry {
281    signature: "mod(a, b)",
282    description: "remainder of a divided by b",
283    example: "get std::math::mod\n\nmod(10, 3) // 1",
284    expected_output: None,
285    returns: "",
286    errors: None,
287    see_also: &[],
288    since: None,
289};
290
291static POW: FnEntry = FnEntry {
292    signature: "pow(a, b)",
293    description: "raises a to the power of b",
294    example: "get std::math::pow\n\npow(2, 2) // 4.0",
295    expected_output: None,
296    returns: "",
297    errors: None,
298    see_also: &[],
299    since: None,
300};
301
302static RADIANS: FnEntry = FnEntry {
303    signature: "radians(x)",
304    description: "convert degrees to radians",
305    example: "get std::math::radians\n\nradians(180.0) // 3.14159...",
306    expected_output: None,
307    returns: "",
308    errors: None,
309    see_also: &[],
310    since: None,
311};
312
313static ROUND: FnEntry = FnEntry {
314    signature: "round(x)",
315    description: "rounds x to the nearest integer",
316    example: "get std::math::round\n\nround(2.2) // 2.0",
317    expected_output: None,
318    returns: "",
319    errors: None,
320    see_also: &[],
321    since: None,
322};
323
324static SIGN: FnEntry = FnEntry {
325    signature: "sign(x)",
326    description: "returns -1, 0, or 1 based on the sign of x",
327    example: "get std::math::sign\n\nsign(-5) // -1",
328    expected_output: None,
329    returns: "",
330    errors: None,
331    see_also: &[],
332    since: None,
333};
334
335static SIN: FnEntry = FnEntry {
336    signature: "sin(x)",
337    description: "sine of x in radians",
338    example: "get std::math::sin\n\nsin(0.0) // 0.0",
339    expected_output: None,
340    returns: "",
341    errors: None,
342    see_also: &[],
343    since: None,
344};
345
346static SQRT: FnEntry = FnEntry {
347    signature: "sqrt(x)",
348    description: "square root of x",
349    example: "get std::math::sqrt\n\nsqrt(4) // 2.0",
350    expected_output: None,
351    returns: "",
352    errors: None,
353    see_also: &[],
354    since: None,
355};
356
357static TAN: FnEntry = FnEntry {
358    signature: "tan(x)",
359    description: "tangent of x in radians",
360    example: "get std::math::tan\n\ntan(0.0) // 0.0",
361    expected_output: None,
362    returns: "",
363    errors: None,
364    see_also: &[],
365    since: None,
366};