Skip to content

Commit

Permalink
compilation fix and adding type traits to ValidateAssignment
Browse files Browse the repository at this point in the history
  • Loading branch information
Ravenwater committed Nov 14, 2024
1 parent 9f96c99 commit 34b01fe
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 27 deletions.
21 changes: 1 addition & 20 deletions include/universal/number/rational/rational_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,29 +143,10 @@ class rational {

// unitary operators
rational operator-() const {
SignedBlockBinary a = n;
SignedBlockBinary b = d;
rational tmp(-n,d);
return tmp;
}
rational operator++(int) { // postfix
rational tmp(*this);
++n;
return tmp;
}
rational& operator++() { // prefix
++n;
return *this;
}
rational operator--(int) { // postfix
rational tmp(*this);
--n;
return tmp;
}
rational& operator--() { // prefix
--n;
return *this;
}
// increment and decrement operators are not defined for rational

// in-place arithmetic assignment operators
rational& operator+=(const rational& rhs) {
Expand Down
14 changes: 7 additions & 7 deletions static/rational/conversion/assignment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@

namespace sw { namespace universal {

// TODO: needs a type trait to only match on rational<> type
template<typename RationalType>
template<typename RationalType,
typename = typename std::enable_if_t<is_rational<RationalType>, RationalType> >
int ValidateAssignment(bool reportTestCases) {
constexpr size_t nbits = RationalType::nbits;
constexpr size_t NR_ENCODINGS = (1ull << nbits);
constexpr unsigned nbits = RationalType::nbits;
static_assert(nbits <= 20, "rational state space is too large to exhaustively test with ValidateAssignment<rational>");

constexpr unsigned NR_ENCODINGS = (1ull << nbits);
int nrOfFailedTestCases = 0;

RationalType a, b;
Expand Down Expand Up @@ -124,11 +126,9 @@ try {
Ranges(1.0f);

// manual exhaustive test
//

nrOfFailedTestCases += ReportTestResult(ValidateAssignment<rb8>(reportTestCases), type_tag(rb8()), test_tag);
nrOfFailedTestCases += ReportTestResult(ValidateAssignment<rb16>(reportTestCases), type_tag(rb16()), test_tag);
// nrOfFailedTestCases += ReportTestResult(ValidateAssignment<rb32>(reportTestCases), type_tag(rb32()), test_tag);
nrOfFailedTestCases += ReportTestResult(ValidateAssignment<rb64>(reportTestCases), type_tag(rb64()), test_tag);

ReportTestSuiteResults(test_suite, nrOfFailedTestCases);
return EXIT_SUCCESS;
Expand Down

0 comments on commit 34b01fe

Please sign in to comment.