From de595b85ce1fb19502a76898192490e9a1ad02ba Mon Sep 17 00:00:00 2001 From: Sergey B Kirpichev Date: Tue, 3 Feb 2026 08:54:39 +0300 Subject: [PATCH] Fix rich comparisons --- gmp.c | 2 +- tests/test_mpz.py | 5 +---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/gmp.c b/gmp.c index 0c51db04..deadbb1f 100644 --- a/gmp.c +++ b/gmp.c @@ -861,7 +861,7 @@ richcompare(PyObject *self, PyObject *other, int op) fallback: Py_RETURN_NOTIMPLEMENTED; numbers: - self = to_float(self); + self = MPZ_to_int((MPZ_Object *)self); if (!self) { return NULL; /* LCOV_EXCL_LINE */ } diff --git a/tests/test_mpz.py b/tests/test_mpz.py index 19792899..bac29f57 100644 --- a/tests/test_mpz.py +++ b/tests/test_mpz.py @@ -362,6 +362,7 @@ def test_repr(x): @given(bigints(), floats()) +@example(9007199254740993, 9007199254740992.0) def test_richcompare_mixed(x, y): mx = mpz(x) for op in [operator.eq, operator.ne, operator.lt, operator.le, @@ -376,10 +377,6 @@ def test_richcompare_errors(): mx > 1j with pytest.raises(TypeError): mx > object() - with pytest.raises(OverflowError): - mpz(10**1000) < 1.1 - with pytest.raises(OverflowError): - mpz(10**1000) > 1.1 def test_hash_caching():