From cc7902ac509b870b268e6664a3e4d0ba7412247e Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 16 Feb 2026 09:09:18 +0000 Subject: [PATCH] Fix set_big_i64/set_big_ui64 zero handling: zero is always represented as small Co-authored-by: nunoplopes <2998477+nunoplopes@users.noreply.github.com> --- src/util/mpz.h | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/util/mpz.h b/src/util/mpz.h index e74da812a..f6ed99689 100644 --- a/src/util/mpz.h +++ b/src/util/mpz.h @@ -605,7 +605,11 @@ public: void set(mpz & a, unsigned val) { set(a, (uint64_t)val); } void set(mpz & a, int64_t val) { - if (mpz::fits_in_small(val) && is_small(a)) { + if (val == 0) { + // Zero is always represented as small + reset(a); + } + else if (mpz::fits_in_small(val) && is_small(a)) { a.set(val); } else { @@ -614,7 +618,11 @@ public: } void set(mpz & a, uint64_t val) { - if (mpz::fits_in_small(val) && is_small(a)) { + if (val == 0) { + // Zero is always represented as small + reset(a); + } + else if (mpz::fits_in_small(val) && is_small(a)) { a.set(static_cast(val)); } else {