Skip to content

Commit

Permalink
SVInt operator< fix. (#928)
Browse files Browse the repository at this point in the history
Co-authored-by: Dolgodvorov Egor Victorovich <[email protected]>
  • Loading branch information
Krym4s and Dolgodvorov Egor Victorovich authored Apr 2, 2024
1 parent 3c5e5e0 commit 3ec5fe0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
17 changes: 5 additions & 12 deletions source/numeric/SVInt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1394,19 +1394,12 @@ logic_t SVInt::operator<(const SVInt& rhs) const {
else
return *this < rhs.extend(bitWidth, bothSigned);
}
// handle signed negatives
if (bothSigned && isNegative() ^ rhs.isNegative())
return logic_t(isNegative());

if (bothSigned) {
// handle negatives
if (isNegative()) {
if (rhs.isNegative())
return -(*this) > -rhs;
else
return logic_t(true);
}
if (rhs.isNegative())
return logic_t(false);
}

// both are positive or both are negative
// or not both are signed
if (isSingleWord())
return logic_t(val < rhs.val);

Expand Down
4 changes: 4 additions & 0 deletions tests/unittests/util/NumericTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,10 @@ TEST_CASE("Comparison") {
CHECK("100'sd99999999999999999999999999"_si >= "-120'sd999999999999977789999"_si);
CHECK("100'd99999999999999999999999999"_si < "-120'sd999999999999977789999"_si);
CHECK("100'd99999999999999999999999999"_si >= -50);
CHECK(SVInt(32, -2147483648, 1) < SVInt(32, -1, 1));
CHECK(SVInt(32, -1, 1) > SVInt(32, -2147483648, 1));
CHECK(SVInt(32, 0, 1) > SVInt(32, -1, 1));
CHECK(SVInt(32, -1, 1) < SVInt(32, 0, 1));

CHECK(bool("100'd1234"_si && "100'd09809345"_si));
CHECK(bool("100'd1234"_si || "100'd0"_si));
Expand Down

0 comments on commit 3ec5fe0

Please sign in to comment.