diff --git a/py/mpz.c b/py/mpz.c index c0a3d4b0b4..a056a6e8ad 100644 --- a/py/mpz.c +++ b/py/mpz.c @@ -820,6 +820,10 @@ bool mpz_is_even(const mpz_t *z) { } int mpz_cmp(const mpz_t *z1, const mpz_t *z2) { + // to catch comparison of -0 with +0 + if (z1->len == 0 && z2->len == 0) { + return 0; + } int cmp = (int)z2->neg - (int)z1->neg; if (cmp != 0) { return cmp; diff --git a/tests/basics/int_big_zeroone.py b/tests/basics/int_big_zeroone.py index e467714bdf..7e0b7a720e 100644 --- a/tests/basics/int_big_zeroone.py +++ b/tests/basics/int_big_zeroone.py @@ -12,3 +12,17 @@ print([-c for c in cases]) print([~c for c in cases]) print([c >> 1 for c in cases]) print([c << 1 for c in cases]) + +# comparison of 0/-0/+0 +print(long_zero == 0) +print(long_neg_zero == 0) +print(long_one - 1 == 0) +print(long_neg_one + 1 == 0) +print(long_zero < 1) +print(long_zero < -1) +print(long_zero > 1) +print(long_zero > -1) +print(long_neg_zero < 1) +print(long_neg_zero < -1) +print(long_neg_zero > 1) +print(long_neg_zero > -1)