Skip to main content

rl_lang/interpreter/stdlib/math/
mod.rs

1//! `std::math` - mathematical functions and the `std::math::consts` submodule.
2//!
3//! Most functions accept both `int` and `float`; mixed types are handled per-function.
4//! `pow` uses `with_raw_function` to handle `(int, int)`, `(int, float)`, `(float, float)`,
5//! and `(float, int)` combinations manually.
6
7mod abs;
8mod acos;
9mod asin;
10mod atan;
11mod atan2;
12mod ceil;
13mod clamp;
14pub mod constants;
15mod cos;
16mod degrees;
17mod exp;
18mod factorial;
19mod fibonacci;
20mod floor;
21mod gcd;
22mod hypot;
23mod is_prime;
24mod lcm;
25mod lerp;
26mod log;
27mod log10;
28mod log2;
29mod map_range;
30mod max;
31mod min;
32mod modulo;
33mod power;
34mod radians;
35mod round;
36mod sign;
37mod sin;
38mod sqrt;
39mod tan;
40
41use crate::interpreter::native::Module;
42
43pub const KEYWORDS: &[&str] = &[
44    "sin",
45    "cos",
46    "tan",
47    "pow",
48    "mod",
49    "abs",
50    "ceil",
51    "clamp",
52    "floor",
53    "round",
54    "log",
55    "log2",
56    "log10",
57    "max",
58    "min",
59    "sqrt",
60    "atan",
61    "acos",
62    "asin",
63    "atan2",
64    "radians",
65    "degrees",
66    "exp",
67    "factorial",
68    "fibonacci",
69    "gcd",
70    "lcm",
71    "hypot",
72    "lerp",
73    "map_range",
74    "sign",
75    "is_prime",
76];
77
78pub fn module() -> Module {
79    Module::new("math")
80        .with_function("sin", sin::std_sin)
81        .with_function("cos", cos::std_cos)
82        .with_function("tan", tan::std_tan)
83        .with_raw_function("pow", power::std_pow)
84        .with_function("mod", modulo::std_mod)
85        .with_function("abs", abs::std_abs)
86        .with_function("ceil", ceil::std_ceil)
87        .with_function("clamp", clamp::std_clamp)
88        .with_function("floor", floor::std_floor)
89        .with_function("round", round::std_round)
90        .with_function("log", log::std_log)
91        .with_function("log2", log2::std_log2)
92        .with_function("log10", log10::std_log10)
93        .with_function("max", max::std_max)
94        .with_function("min", min::std_min)
95        .with_function("sqrt", sqrt::std_sqrt)
96        .with_function("atan", atan::std_atan)
97        .with_function("atan2", atan2::std_atan2)
98        .with_function("acos", acos::std_acos)
99        .with_function("asin", asin::std_asin)
100        .with_function("degrees", degrees::std_degrees)
101        .with_function("radians", radians::std_radians)
102        .with_function("exp", exp::std_exp)
103        .with_function("factorial", factorial::std_factorial)
104        .with_function("fibonacci", fibonacci::std_fibonacci)
105        .with_function("gcd", gcd::std_gcd)
106        .with_function("lcm", lcm::std_lcm)
107        .with_function("lerp", lerp::std_lerp)
108        .with_function("is_prime", is_prime::std_is_prime)
109        .with_function("hypot", hypot::std_hypot)
110        .with_function("sign", sign::std_sign)
111        .with_function("map_range", map_range::std_map_range)
112        .with_module(constants::module())
113}