mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 11:30:18 +00:00
...
This commit is contained in:
parent
393302ae85
commit
e107531862
@ -4,9 +4,6 @@ def print(*args, sep=' ', end='\n'):
|
||||
s = sep.join([str(i) for i in args])
|
||||
_sys.stdout.write(s + end)
|
||||
|
||||
def abs(x):
|
||||
return -x if x < 0 else x
|
||||
|
||||
def max(*args, key=None):
|
||||
if key is None:
|
||||
key = lambda x: x
|
||||
|
@ -139,14 +139,6 @@ void init_builtins(VM* _vm) {
|
||||
return VAR(MappingProxy(mod));
|
||||
});
|
||||
|
||||
// def round(x, ndigits=0):
|
||||
// assert ndigits >= 0
|
||||
// if ndigits == 0:
|
||||
// return int(x + 0.5) if x >= 0 else int(x - 0.5)
|
||||
// if x >= 0:
|
||||
// return int(x * 10**ndigits + 0.5) / 10**ndigits
|
||||
// else:
|
||||
// return int(x * 10**ndigits - 0.5) / 10**ndigits
|
||||
_vm->bind(_vm->builtins, "round(x, ndigits=0)", [](VM* vm, ArgsView args) {
|
||||
f64 x = CAST(f64, args[0]);
|
||||
int ndigits = CAST(int, args[1]);
|
||||
@ -161,6 +153,13 @@ void init_builtins(VM* _vm) {
|
||||
}
|
||||
});
|
||||
|
||||
_vm->bind_builtin_func<1>("abs", [](VM* vm, ArgsView args) {
|
||||
if(is_int(args[0])) return VAR(std::abs(_CAST(i64, args[0])));
|
||||
if(is_float(args[0])) return VAR(std::abs(_CAST(f64, args[0])));
|
||||
vm->TypeError("bad operand type for abs()");
|
||||
return vm->None;
|
||||
});
|
||||
|
||||
_vm->bind_builtin_func<1>("id", [](VM* vm, ArgsView args) {
|
||||
PyObject* obj = args[0];
|
||||
if(is_tagged(obj)) return vm->None;
|
||||
|
Loading…
x
Reference in New Issue
Block a user