From 1826601a14792f6c67427293d5a2df579a7d332d Mon Sep 17 00:00:00 2001 From: Oscar Puente Date: Mon, 27 Apr 2026 20:51:34 -0700 Subject: [PATCH] remove int overflow check Co-authored-by: Copilot --- source/pip/qsharp/_adaptive_pass.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/source/pip/qsharp/_adaptive_pass.py b/source/pip/qsharp/_adaptive_pass.py index f5c731cd76..d1d4a9b6ac 100644 --- a/source/pip/qsharp/_adaptive_pass.py +++ b/source/pip/qsharp/_adaptive_pass.py @@ -217,13 +217,16 @@ class IntOperand: bits: int def __post_init__(self): - # Mask to the appropriate word-width so negative Python ints become - # their two's-complement representation + # Mask to the appropriate word-width so negative Python ints and + # wider-than-target constants become their two's-complement + # representation at the target bit width # (e.g. -7 → 0xFFFFFFF9 for 32-bit, 0xFFFFFFFFFFFFFFF9 for 64-bit). + # + # Note: we have no way to tell if a negative number, represented by + # pyqir as an u64 is an overflow or just a negative number. + # therefore we don't perform overflow checks here, and instead + # default to a wrapping behavior. mask = (1 << self.bits) - 1 - min_val = -(1 << (self.bits - 1)) - if self.val < min_val or self.val > mask: - raise ValueError(f"Value {self.val} does not fit in {self.bits} bits") self.val = self.val & mask