py/objint: Handle special case of -0 when classifying fp as int.

Otherwise -0.0 is classified as a bigint, which for builds without bigints
will lead unexpectedly to an overflow.
This commit is contained in:
Damien George 2017-03-23 23:51:35 +11:00
parent febeff4af4
commit c073519ec8

View File

@ -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);
}