diff --git a/src/pocketpy.h b/src/pocketpy.h index 9c775b33..c75c1400 100644 --- a/src/pocketpy.h +++ b/src/pocketpy.h @@ -577,6 +577,9 @@ void add_module_math(VM* vm){ vm->bind_func<1>(mod, "tan", CPP_LAMBDA(vm->PyFloat(tan(vm->num_to_float(args[0]))))); vm->bind_func<1>(mod, "isnan", CPP_LAMBDA(vm->PyBool(std::isnan(vm->num_to_float(args[0]))))); vm->bind_func<1>(mod, "isinf", CPP_LAMBDA(vm->PyBool(std::isinf(vm->num_to_float(args[0]))))); + vm->bind_func<1>(mod, "fabs", CPP_LAMBDA(vm->PyFloat(std::fabs(vm->num_to_float(args[0]))))); + vm->bind_func<1>(mod, "floor", CPP_LAMBDA(vm->PyInt(std::floor(vm->num_to_float(args[0]))))); + vm->bind_func<1>(mod, "ceil", CPP_LAMBDA(vm->PyInt(std::ceil(vm->num_to_float(args[0]))))); } void add_module_dis(VM* vm){ diff --git a/tests/_math.py b/tests/_math.py index 535b8727..add480d9 100644 --- a/tests/_math.py +++ b/tests/_math.py @@ -1,4 +1,4 @@ -from math import log, log10, log2, sin, cos, tan, e, pi, isnan, isinf +from math import log, log10, log2, sin, cos, tan, e, pi, isnan, isinf, fabs, floor, ceil def isclose(a, b): return abs(a-b) < 0.000001 @@ -16,4 +16,11 @@ a = -0.1 a = a**a assert isnan(a) assert not isinf(a) -assert isinf(float("inf")) \ No newline at end of file +assert isinf(float("inf")) + +assert isclose(fabs(-1.2), 1.2) + +assert floor(1.2) == 1 +assert floor(-1.2) == -2 +assert ceil(1.2) == 2 +assert ceil(-1.2) == -1 \ No newline at end of file