← index #6332Issue #1064
Related · high · value 4.184
QUERY · ISSUE

Overflow converting -2147483648 to int when using MPZ

openby markstzopened 2020-08-12updated 2020-08-12
py-core

When MICROPY_LONGINT_IMPL == MICROPY_LONGINT_IMPL_MPZ, calling mp_obj_get_int() for a Python variable that contains the value -2147483648 results in an overflow converting long int to machine word error.

If MICROPY_LONGINT_IMPL == MICROPY_LONGINT_IMPL_LONGLONG instead, the conversion works OK.

Is the MPZ overflow check incorrect?

CANDIDATE · ISSUE

Converting minimum long long value to string results in incorrect output

closedby doogleopened 2015-01-13updated 2017-04-11

When mp is configured to use 'long long' ints (MICROPY_LONGINT_IMPL == MICROPY_LONGINT_IMPL_LONGLONG), the following code:

print(-0x7fffffffffffffff-1)

results in the string:

-'..--).0-*(+,))+(0(

rather than:

-9223372036854775808

This is due to mp_obj_int_formatted() trying to negate the number, which fails in this case. The subsequent conversion to a string then results in invalid characters due to (I think) signedness issues.

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied