mirror of
https://github.com/micropython/micropython.git
synced 2026-01-05 19:50:30 +01:00
py/mpz: Do sign extension in mpz_as_bytes for negative values.
Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
@@ -36,3 +36,11 @@ print(struct.unpack("<Q", b"\xff\xff\xff\xff\xff\xff\xff\xff"))
|
||||
# check small int overflow
|
||||
print(struct.unpack("<i", b'\xff\xff\xff\x7f'))
|
||||
print(struct.unpack("<q", b'\xff\xff\xff\xff\xff\xff\xff\x7f'))
|
||||
|
||||
# test with negative big integers that are actually small in magnitude
|
||||
bigzero = (1 << 70) - (1 << 70)
|
||||
for endian in "<>":
|
||||
for type_ in "bhiq":
|
||||
fmt = endian + type_
|
||||
b = struct.pack(fmt, -2 + bigzero)
|
||||
print(fmt, b, struct.unpack(fmt, b))
|
||||
|
||||
Reference in New Issue
Block a user