This commit is contained in:
blueloveTH 2023-05-01 19:33:49 +08:00
parent a0770d4191
commit 1444c4b380
3 changed files with 11 additions and 1 deletions

View File

@ -58,3 +58,7 @@ Return the smallest integer value greater than or equal to `x`.
### `math.sqrt(x)`
Return the square root of `x`.
### `math.gcd(a, b)`
Return the greatest common divisor of `a` and `b`.

View File

@ -4,7 +4,7 @@ label: requests
---
!!!
This module is experimental. To enable it, download `httplib.h` from https://github.com/yhirose/cpp-httplib and place it in the same directory as `pocketpy.h`.
This module is experimental. To enable it, download `httplib.h` from [here](https://github.com/yhirose/cpp-httplib) and place it in the same directory as `pocketpy.h`.
SSL is not supported.
!!!

View File

@ -775,6 +775,12 @@ inline void add_module_math(VM* vm){
vm->bind_func<1>(mod, "floor", CPP_LAMBDA(VAR((i64)std::floor(vm->num_to_float(args[0])))));
vm->bind_func<1>(mod, "ceil", CPP_LAMBDA(VAR((i64)std::ceil(vm->num_to_float(args[0])))));
vm->bind_func<1>(mod, "sqrt", CPP_LAMBDA(VAR(std::sqrt(vm->num_to_float(args[0])))));
vm->bind_func<2>(mod, "gcd", [](VM* vm, ArgsView args) {
i64 a = CAST(i64, args[0]);
i64 b = CAST(i64, args[1]);
a = std::gcd(a, b);
return VAR(a);
});
}
inline void add_module_dis(VM* vm){