Skip to content

Commit

Permalink
bug fix of bitnplusone calculation in divround of posit<16,2>
Browse files Browse the repository at this point in the history
  • Loading branch information
Ravenwater committed Jan 2, 2024
1 parent 40a475a commit 7e149f7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
4 changes: 1 addition & 3 deletions include/universal/number/posit/specialized/posit_16_2.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -863,9 +863,7 @@ class posit<NBITS_IS_16, ES_IS_2> {
uint16_t final_fbits = uint16_t(fraction >> (reglen + 2));
bool bitNPlusOne = false;
if (reglen != 14) {
//std::cout << "fraction : " << to_binary(fraction, 16, true) << '\n';
//std::cout << "nplusone : " << to_binary((fraction >> (reglen - 1)), 16, true) << '\n';
bitNPlusOne = bool((fraction >> (reglen - 1)) & 0x1);
bitNPlusOne = bool((fraction >> (reglen + 1)) & 0x1);
}
else if (final_fbits > 0) {
final_fbits = 0;
Expand Down
11 changes: 9 additions & 2 deletions static/posit/specialized/posit_16_2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,19 @@ try {

#if MANUAL_TESTING

TestWithValues(-9.0390625, -0.0225372314453125);
TestWithValues(1.1368683772161602974e-13, 8.5265128291212022305e-14);
/*
-0.3614501953125 /= -281474976710656 != 2.2204460492503130808e-16 golden reference is 8.8817841970012523234e-16
0b1.01.10.01110010001 /= 0b1.11111111111110.0. != 0b0.00000000000001.0. golden reference is 0b0.00000000000001.1.
*/
TestWithValues(-0.3614501953125, -281474976710656);

nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms<nbits, es>(reportTestCases, OPCODE_IPA, 100), tag, "+= (native) ");
nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms<nbits, es>(reportTestCases, OPCODE_IPS, 100), tag, "-= (native) ");
nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms<nbits, es>(reportTestCases, OPCODE_IPM, 100), tag, "*= (native) ");
nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms<nbits, es>(true, OPCODE_IPD, 100), tag, "/= (native) ");
nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms<nbits, es>(reportTestCases, OPCODE_IPD, 100), tag, "/= (native) ");

TestWithValues(1.1368683772161602974e-13, 8.5265128291212022305e-14);
goto epilog;

std::cout << "Exhaustive tests" << std::endl;
Expand Down

0 comments on commit 7e149f7

Please sign in to comment.