summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--py/objint.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/py/objint.c b/py/objint.c
index 5aa6a95cc0..ce091549d4 100644
--- a/py/objint.c
+++ b/py/objint.c
@@ -103,7 +103,12 @@ mp_fp_as_int_class_t mp_classify_fp_as_int(mp_float_t val) {
#if MICROPY_FLOAT_IMPL == MICROPY_FLOAT_IMPL_DOUBLE
e |= u.i[MP_ENDIANNESS_BIG] != 0;
#endif
- e += ((1 << MP_FLOAT_EXP_BITS) - 1) << MP_FLOAT_EXP_SHIFT_I32;
+ if ((e & ~(1 << MP_FLOAT_SIGN_SHIFT_I32)) == 0) {
+ // handle case of -0 (when sign is set but rest of bits are zero)
+ e = 0;
+ } else {
+ e += ((1 << MP_FLOAT_EXP_BITS) - 1) << MP_FLOAT_EXP_SHIFT_I32;
+ }
} else {
e &= ~((1 << MP_FLOAT_EXP_SHIFT_I32) - 1);
}