Skip to content

Commit

Permalink
Fix abs() on symbolic boolean
Browse files Browse the repository at this point in the history
  • Loading branch information
pschanely committed Jul 23, 2024
1 parent 4ad30d3 commit 7394bcd
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
4 changes: 4 additions & 0 deletions crosshair/libimpl/builtinslib.py
Original file line number Diff line number Diff line change
Expand Up @@ -1058,6 +1058,10 @@ def __ch_realize__(self) -> object:
with NoTracing():
return context_statespace().choose_possible(self.var)

def __abs__(self):
with NoTracing():
return SymbolicInt(z3.If(self.var, 1, 0))

def __neg__(self):
with NoTracing():
return SymbolicInt(z3.If(self.var, -1, 0))
Expand Down
2 changes: 1 addition & 1 deletion crosshair/libimpl/builtinslib_ch_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
)


def check_abs(x: float) -> ResultComparison:
def check_abs(x: Union[int, bool, float]) -> ResultComparison:
"""post: _"""
return compare_results(abs, x)

Expand Down
3 changes: 2 additions & 1 deletion doc/source/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ Changelog
Next Version
------------

* Nothing yet!
* Fix spurious error calling ``abs()`` on a symbolic boolean.
(fixes `#283 <https://github.com/pschanely/CrossHair/issues/283>`__)


Version 0.0.64
Expand Down

0 comments on commit 7394bcd

Please sign in to comment.