From ded37fa0128cd5de901ebddbe1a7a8a805dc4c38 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 13 Feb 2026 13:48:38 +0000 Subject: [PATCH] Fix machine_div2k to not truncate when result doesn't fit in small (add assertion instead) Co-authored-by: nunoplopes <2998477+nunoplopes@users.noreply.github.com> --- src/util/mpz.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/util/mpz.cpp b/src/util/mpz.cpp index 76a89c09a..48c8229f9 100644 --- a/src/util/mpz.cpp +++ b/src/util/mpz.cpp @@ -2126,11 +2126,10 @@ void mpz_manager::machine_div2k(mpz & a, unsigned k) { if (k < 32) { int64_t twok = 1ull << ((int64_t)k); int64_t val = a.value64(); - if (mpz::fits_in_small(val/twok)) { - a.set64(val/twok); - } else { - a.set((int)(val/twok)); - } + int64_t result = val / twok; + // Division by power of 2 should keep us in small range + SASSERT(mpz::fits_in_small(result)); + a.set64(result); } else if (k < 64) { int64_t twok = 1ull << ((int64_t)k);