Skip to content

Commit 758c550

Browse files
ishuahIshuah Kariuki
and
Ishuah Kariuki
authored
Bugfix: Division Bug in Programmer Dec Mode (#2300)
* Update intrat function added a programmer mode test case * Added three more test cases --------- Co-authored-by: Ishuah Kariuki <[email protected]>
1 parent 71454ce commit 758c550

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

src/CalcManager/Ratpack/support.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,12 @@ void intrat(_Inout_ PRAT* px, uint32_t radix, int32_t precision)
303303
DUPRAT(pret, *px);
304304
remrat(&pret, rat_one);
305305

306+
// Flatten pret in case it's not aligned with px after remrat operation
307+
if (!equnum((*px)->pq, pret->pq))
308+
{
309+
flatrat(pret, radix, precision);
310+
}
311+
306312
subrat(px, pret, precision);
307313
destroyrat(pret);
308314

src/CalculatorUnitTests/CalculatorManagerTest.cpp

+25
Original file line numberDiff line numberDiff line change
@@ -752,6 +752,31 @@ namespace CalculatorManagerTest
752752

753753
Command commands10[] = { Command::ModeProgrammer, Command::Command1, Command::CommandRORC, Command::CommandRORC, Command::CommandNULL };
754754
TestDriver::Test(L"-9,223,372,036,854,775,808", L"RoR(RoR(1))", commands10, true, false);
755+
756+
Command commands11[] = { Command::ModeProgrammer, Command::CommandDec, Command::Command4, Command::Command2, Command::Command9, Command::Command4,
757+
Command::Command9, Command::Command6, Command::Command7, Command::Command2, Command::Command9, Command::Command6,
758+
Command::CommandDIV, Command::Command2, Command::Command5, Command::Command5, Command::CommandEQU, Command::CommandNULL };
759+
TestDriver::Test(L"16,843,009", L"4294967296 \x00F7 255=", commands11, true, false);
760+
761+
Command commands12[] = {
762+
Command::ModeProgrammer, Command::CommandDec, Command::Command4, Command::Command2, Command::Command9, Command::Command4,
763+
Command::Command9, Command::Command6, Command::Command7, Command::Command3, Command::Command0, Command::Command3,
764+
Command::CommandDIV, Command::Command2, Command::Command5, Command::Command5, Command::CommandEQU, Command::CommandNULL
765+
};
766+
TestDriver::Test(L"16,843,009", L"4294967303 \x00F7 255=", commands12, true, false);
767+
768+
Command commands13[] = {
769+
Command::ModeProgrammer, Command::CommandDec, Command::Command1, Command::Command0, Command::Command0, Command::Command0,
770+
Command::Command0, Command::Command0, Command::Command0, Command::Command0, Command::Command0, Command::Command0, Command::CommandDIV,
771+
Command::Command6, Command::Command4, Command::Command4, Command::Command8, Command::Command7, Command::CommandEQU, Command::CommandNULL
772+
};
773+
TestDriver::Test(L"15,507", L"1000000000 \x00F7 64487=", commands13, true, false);
774+
775+
Command commands14[] = { Command::ModeProgrammer, Command::CommandDec, Command::Command1, Command::Command0, Command::Command0,
776+
Command::Command0, Command::Command0, Command::Command0, Command::Command0, Command::Command0,
777+
Command::Command0, Command::Command0, Command::CommandDIV, Command::Command6, Command::Command4,
778+
Command::Command4, Command::Command8, Command::Command8, Command::CommandEQU, Command::CommandNULL };
779+
TestDriver::Test(L"15,506", L"1000000000 \x00F7 64488=", commands14, true, false);
755780
}
756781

757782
void CalculatorManagerTest::CalculatorManagerTestMemory()

0 commit comments

Comments
 (0)