diff --git a/benchmarks/simple.py b/benchmarks/simple.py index f59c9136..ca0489b6 100644 --- a/benchmarks/simple.py +++ b/benchmarks/simple.py @@ -17,4 +17,4 @@ def test(n): # dis(test) # dis(is_prime) -print(test(10000)) \ No newline at end of file +assert test(10000) == 1229 \ No newline at end of file diff --git a/src/pocketpy.h b/src/pocketpy.h index c75c1400..2a532f03 100644 --- a/src/pocketpy.h +++ b/src/pocketpy.h @@ -580,6 +580,7 @@ void add_module_math(VM* vm){ 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]))))); + vm->bind_func<1>(mod, "sqrt", CPP_LAMBDA(vm->PyFloat(std::sqrt(vm->num_to_float(args[0]))))); } void add_module_dis(VM* vm){ diff --git a/tests/_math.py b/tests/_math.py index add480d9..0545aabc 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, fabs, floor, ceil +from math import log, log10, log2, sin, cos, tan, e, pi, isnan, isinf, fabs, floor, ceil, sqrt def isclose(a, b): return abs(a-b) < 0.000001 @@ -23,4 +23,6 @@ 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 +assert ceil(-1.2) == -1 + +assert isclose(sqrt(4), 2.0) \ No newline at end of file