mirror of
https://github.com/micropython/micropython.git
synced 2026-01-04 19:20:22 +01:00
py: Fix check of small-int overflow when parsing ints.
Also unifies use of SMALL_INT_FITS macro across parser and runtime.
This commit is contained in:
@@ -26,6 +26,11 @@
|
||||
|
||||
// Functions for small integer arithmetic
|
||||
|
||||
// In SMALL_INT, next-to-highest bits is used as sign, so both must match for value in range
|
||||
#define MP_SMALL_INT_MIN ((mp_small_int_t)(((machine_int_t)WORD_MSBIT_HIGH) >> 1))
|
||||
#define MP_SMALL_INT_MAX ((mp_small_int_t)(~(MP_SMALL_INT_MIN)))
|
||||
#define MP_SMALL_INT_FITS(n) ((((n) ^ ((n) << 1)) & WORD_MSBIT_HIGH) == 0)
|
||||
|
||||
bool mp_small_int_mul_overflow(machine_int_t x, machine_int_t y);
|
||||
machine_int_t mp_small_int_modulo(machine_int_t dividend, machine_int_t divisor);
|
||||
machine_int_t mp_small_int_floor_divide(machine_int_t num, machine_int_t denom);
|
||||
|
||||
Reference in New Issue
Block a user