summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Epler <jepler@gmail.com>2025-07-15 18:49:51 +0100
committerDamien George <damien@micropython.org>2025-09-28 23:24:24 +1000
commitf658b0d862cb4eafe8df5bd22cb1302d83da4938 (patch)
treeae8ff57b8ed2c8e3b26b909f7734fdaa56180671
parente35ac67421f71c430ce7a0b26532b048aa4528cd (diff)
py/objint: Fix converting float to int with OBJ_REPR_B.
The check for 'fits in a small int' is specific to the 31-bit int of other object representations. Signed-off-by: Jeff Epler <jepler@unpythonic.net>
-rw-r--r--py/objint.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/py/objint.c b/py/objint.c
index fd9ab106f..901264aca 100644
--- a/py/objint.c
+++ b/py/objint.c
@@ -117,9 +117,15 @@ static mp_fp_as_int_class_t mp_classify_fp_as_int(mp_float_t val) {
}
// 8 * sizeof(uintptr_t) counts the number of bits for a small int
// TODO provide a way to configure this properly
+ #if MICROPY_OBJ_REPR == MICROPY_OBJ_REPR_B
+ if (e <= ((8 * sizeof(uintptr_t) + MP_FLOAT_EXP_BIAS - 4) << MP_FLOAT_EXP_SHIFT_I32)) {
+ return MP_FP_CLASS_FIT_SMALLINT;
+ }
+ #else
if (e <= ((8 * sizeof(uintptr_t) + MP_FLOAT_EXP_BIAS - 3) << MP_FLOAT_EXP_SHIFT_I32)) {
return MP_FP_CLASS_FIT_SMALLINT;
}
+ #endif
#if MICROPY_LONGINT_IMPL == MICROPY_LONGINT_IMPL_LONGLONG
if (e <= (((sizeof(long long) * MP_BITS_PER_BYTE) + MP_FLOAT_EXP_BIAS - 2) << MP_FLOAT_EXP_SHIFT_I32)) {
return MP_FP_CLASS_FIT_LONGINT;