From 3e1fe4487ec56a5704afdcc8629c39c7145fc1e0 Mon Sep 17 00:00:00 2001 From: Alexander Scheel Date: Wed, 13 Mar 2024 20:56:52 -0400 Subject: [PATCH] Avoid attempting to negate negative integers Negative integers can have a variety of forms (two's compliment or otherwise or sign and magnitude), and thus should be negated manually prior to passing in to conversion. Signed-off-by: Alexander Scheel --- python/vec.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/python/vec.py b/python/vec.py index 8256909..0630a85 100644 --- a/python/vec.py +++ b/python/vec.py @@ -536,6 +536,8 @@ def _from_arg_(arg: Union[VectorLike, Vector], have_model: bool = False) -> tupl # ret: [Vector/list/tuple], model, is_fixed if isinstance(arg, int): + if arg < 0: + raise ValueError(f"unable to convert negative int ({arg}) to array: negate manually at the desired width via l_not") value = list(map(lambda x: bool(int(x)), bin(arg)[2:])) return value, None, False