Skip to content

Commit

Permalink
Avoid attempting to negate negative integers
Browse files Browse the repository at this point in the history
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 <alexander.m.scheel@gmail.com>
  • Loading branch information
cipherboy committed Mar 14, 2024
1 parent 599a7bd commit 3e1fe44
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions python/vec.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 3e1fe44

Please sign in to comment.