From 1444c4b380a6fb43217ca0984bb039cc819d753f Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Mon, 1 May 2023 19:33:49 +0800 Subject: [PATCH] ... --- docs/modules/math.md | 4 ++++ docs/modules/requests.md | 2 +- src/pocketpy.h | 6 ++++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/docs/modules/math.md b/docs/modules/math.md index c0ea005c..4ac12475 100644 --- a/docs/modules/math.md +++ b/docs/modules/math.md @@ -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`. \ No newline at end of file diff --git a/docs/modules/requests.md b/docs/modules/requests.md index 347c4ef7..4533cc15 100644 --- a/docs/modules/requests.md +++ b/docs/modules/requests.md @@ -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. !!! diff --git a/src/pocketpy.h b/src/pocketpy.h index 1a7ab4ac..ae31db8e 100644 --- a/src/pocketpy.h +++ b/src/pocketpy.h @@ -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){