mirror of
https://github.com/micropython/micropython.git
synced 2026-01-04 19:20:22 +01:00
py: Fix builtin abs so it works for bools and bignum.
This commit is contained in:
10
py/objint.c
10
py/objint.c
@@ -266,6 +266,16 @@ bool mp_obj_int_is_positive(mp_obj_t self_in) {
|
||||
return mp_obj_get_int(self_in) >= 0;
|
||||
}
|
||||
|
||||
// This must handle int and bool types, and must raise a
|
||||
// TypeError if the argument is not integral
|
||||
mp_obj_t mp_obj_int_abs(mp_obj_t self_in) {
|
||||
mp_int_t val = mp_obj_get_int(self_in);
|
||||
if (val < 0) {
|
||||
val = -val;
|
||||
}
|
||||
return MP_OBJ_NEW_SMALL_INT(val);
|
||||
}
|
||||
|
||||
// This is called for operations on SMALL_INT that are not handled by mp_unary_op
|
||||
mp_obj_t mp_obj_int_unary_op(mp_uint_t op, mp_obj_t o_in) {
|
||||
return MP_OBJ_NULL; // op not supported
|
||||
|
||||
Reference in New Issue
Block a user