Skip to content

Commit da3dffa

Browse files
committed
py/objint: Fix classification of float so it works for OBJ_REPR_D.
1 parent 2adf7ec commit da3dffa

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

py/objint.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,9 @@ mp_fp_as_int_class_t mp_classify_fp_as_int(mp_float_t val) {
107107
} else {
108108
e &= ~((1 << MP_FLOAT_EXP_SHIFT_I32) - 1);
109109
}
110-
if (e <= ((BITS_PER_WORD + MP_FLOAT_EXP_BIAS - 3) << MP_FLOAT_EXP_SHIFT_I32)) {
110+
// 8 * sizeof(uintptr_t) counts the number of bits for a small int
111+
// TODO provide a way to configure this properly
112+
if (e <= ((8 * sizeof(uintptr_t) + MP_FLOAT_EXP_BIAS - 3) << MP_FLOAT_EXP_SHIFT_I32)) {
111113
return MP_FP_CLASS_FIT_SMALLINT;
112114
}
113115
#if MICROPY_LONGINT_IMPL == MICROPY_LONGINT_IMPL_LONGLONG

0 commit comments

Comments
 (0)