Skip to content

Commit

Permalink
bug fix and reporting improvement of posit randoms
Browse files Browse the repository at this point in the history
  • Loading branch information
Ravenwater committed Dec 24, 2023
1 parent 201fe04 commit 50e3efe
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions include/universal/verification/posit_test_randoms.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,8 @@ namespace sw { namespace universal {
std::mt19937_64 eng(rd()); // use the 64-bit Mersenne Twister 19937 generator and seed it with entropy.
// define the distribution, by default it goes from 0 to MAX(unsigned long long)
std::uniform_int_distribution<unsigned long long> distr;
bool firstNaRCall = true;
bool firstDivideByZeroCall = true;
int nrOfFailedTests = 0;
for (unsigned i = 1; i < nrOfRandoms; i++) {
posit<nbits, es> testa, testb, testc, testref;
Expand All @@ -260,8 +262,15 @@ namespace sw { namespace universal {
executeBinary(opcode, da, db, dc, testa, testb, testc, testref);
}
catch (const posit_arithmetic_exception& err) {
if (testa.isnar() || testb.isnar() || ((opcode == OPCODE_DIV || opcode == OPCODE_IPD) && testb.iszero())) {
if (reportTestCases) std::cerr << "Correctly caught arithmetic exception: " << err.what() << std::endl;
if (testa.isnar() || testb.isnar()) {
if (reportTestCases && firstNaRCall) std::cerr << "Correctly caught arithmetic exception: " << err.what() << std::endl;
firstNaRCall = false;
continue;
}
else if (((opcode == OPCODE_DIV || opcode == OPCODE_IPD) && testb.iszero())) {
if (reportTestCases && firstDivideByZeroCall) std::cerr << "Correctly caught arithmetic exception: " << err.what() << std::endl;
firstDivideByZeroCall = false;
continue;
}
else {
throw; // rethrow
Expand Down

0 comments on commit 50e3efe

Please sign in to comment.