mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 11:30:18 +00:00
Merge pull request #9 from gacheiro/main
Add `fabs`, `floor` and `ceil` to `math` module
This commit is contained in:
commit
f818c40398
@ -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){
|
||||
|
@ -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
|
||||
@ -17,3 +17,10 @@ a = a**a
|
||||
assert isnan(a)
|
||||
assert not isinf(a)
|
||||
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
|
Loading…
x
Reference in New Issue
Block a user