Update simple.py

add `sqrt` to math
This commit is contained in:
blueloveTH 2023-02-11 00:11:59 +08:00
parent f818c40398
commit b6bb543c84
3 changed files with 6 additions and 3 deletions

View File

@ -17,4 +17,4 @@ def test(n):
# dis(test)
# dis(is_prime)
print(test(10000))
assert test(10000) == 1229

View File

@ -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){

View File

@ -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
assert ceil(-1.2) == -1
assert isclose(sqrt(4), 2.0)