MCPcopy Index your code
hub / github.com/aiscriptdev/aiscript / create_math_module

Function create_math_module

aiscript-vm/src/stdlib/math.rs:7–47  ·  view source on GitHub ↗
(ctx: Context)

Source from the content-addressed store, hash-verified

5};
6
7pub fn create_math_module(ctx: Context) -> ModuleKind {
8 let name = ctx.intern(b"std.math");
9
10 let exports = [
11 // Constants
12 ("PI", Value::Number(std::f64::consts::PI)),
13 ("E", Value::Number(std::f64::consts::E)),
14 ("TAU", Value::Number(std::f64::consts::TAU)),
15 ("INFINITY", Value::Number(f64::INFINITY)),
16 ("NEG_INFINITY", Value::Number(f64::NEG_INFINITY)),
17 ("NAN", Value::Number(f64::NAN)),
18 // Functions
19 ("add", Value::NativeFunction(NativeFn(math_add))),
20 ("sub", Value::NativeFunction(NativeFn(math_sub))),
21 ("mul", Value::NativeFunction(NativeFn(math_mul))),
22 ("div", Value::NativeFunction(NativeFn(math_div))),
23 ("floo_div", Value::NativeFunction(NativeFn(math_floor_div))),
24 // Advanced functions
25 ("sqrt", Value::NativeFunction(NativeFn(math_sqrt))),
26 ("pow", Value::NativeFunction(NativeFn(math_pow))),
27 ("log", Value::NativeFunction(NativeFn(math_log))),
28 // Trigonometric functions
29 ("sin", Value::NativeFunction(NativeFn(math_sin))),
30 ("cos", Value::NativeFunction(NativeFn(math_cos))),
31 ("tan", Value::NativeFunction(NativeFn(math_tan))),
32 ("asin", Value::NativeFunction(NativeFn(math_asin))),
33 ("acos", Value::NativeFunction(NativeFn(math_acos))),
34 // Rounding functions
35 ("floor", Value::NativeFunction(NativeFn(math_floor))),
36 ("ceil", Value::NativeFunction(NativeFn(math_ceil))),
37 ("round", Value::NativeFunction(NativeFn(math_round))),
38 // Utility functions
39 ("abs", Value::NativeFunction(NativeFn(math_abs))),
40 ("min", Value::NativeFunction(NativeFn(math_min))),
41 ("max", Value::NativeFunction(NativeFn(math_max))),
42 ]
43 .into_iter()
44 .map(|(name, f)| (ctx.intern_static(name), f))
45 .collect();
46 ModuleKind::Native { name, exports }
47}
48
49// Basic arithmetic functions
50fn math_add<'gc>(_state: &mut State<'gc>, args: Vec<Value<'gc>>) -> Result<Value<'gc>, VmError> {

Callers 1

init_stdlibMethod · 0.85

Calls 3

NativeFnClass · 0.85
internMethod · 0.45
intern_staticMethod · 0.45

Tested by

no test coverage detected