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 <ikariuki@microsoft.com>
This commit is contained in:
Ishuah E Kariuki 2025-02-19 10:18:21 +03:00 committed by GitHub
parent 71454cee1f
commit 758c5505c6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 31 additions and 0 deletions

View file

@ -303,6 +303,12 @@ void intrat(_Inout_ PRAT* px, uint32_t radix, int32_t precision)
DUPRAT(pret, *px); DUPRAT(pret, *px);
remrat(&pret, rat_one); remrat(&pret, rat_one);
// Flatten pret in case it's not aligned with px after remrat operation
if (!equnum((*px)->pq, pret->pq))
{
flatrat(pret, radix, precision);
}
subrat(px, pret, precision); subrat(px, pret, precision);
destroyrat(pret); destroyrat(pret);

View file

@ -752,6 +752,31 @@ namespace CalculatorManagerTest
Command commands10[] = { Command::ModeProgrammer, Command::Command1, Command::CommandRORC, Command::CommandRORC, Command::CommandNULL }; Command commands10[] = { Command::ModeProgrammer, Command::Command1, Command::CommandRORC, Command::CommandRORC, Command::CommandNULL };
TestDriver::Test(L"-9,223,372,036,854,775,808", L"RoR(RoR(1))", commands10, true, false); TestDriver::Test(L"-9,223,372,036,854,775,808", L"RoR(RoR(1))", commands10, true, false);
Command commands11[] = { Command::ModeProgrammer, Command::CommandDec, Command::Command4, Command::Command2, Command::Command9, Command::Command4,
Command::Command9, Command::Command6, Command::Command7, Command::Command2, Command::Command9, Command::Command6,
Command::CommandDIV, Command::Command2, Command::Command5, Command::Command5, Command::CommandEQU, Command::CommandNULL };
TestDriver::Test(L"16,843,009", L"4294967296 \x00F7 255=", commands11, true, false);
Command commands12[] = {
Command::ModeProgrammer, Command::CommandDec, Command::Command4, Command::Command2, Command::Command9, Command::Command4,
Command::Command9, Command::Command6, Command::Command7, Command::Command3, Command::Command0, Command::Command3,
Command::CommandDIV, Command::Command2, Command::Command5, Command::Command5, Command::CommandEQU, Command::CommandNULL
};
TestDriver::Test(L"16,843,009", L"4294967303 \x00F7 255=", commands12, true, false);
Command commands13[] = {
Command::ModeProgrammer, Command::CommandDec, Command::Command1, Command::Command0, Command::Command0, Command::Command0,
Command::Command0, Command::Command0, Command::Command0, Command::Command0, Command::Command0, Command::Command0, Command::CommandDIV,
Command::Command6, Command::Command4, Command::Command4, Command::Command8, Command::Command7, Command::CommandEQU, Command::CommandNULL
};
TestDriver::Test(L"15,507", L"1000000000 \x00F7 64487=", commands13, true, false);
Command commands14[] = { Command::ModeProgrammer, Command::CommandDec, Command::Command1, Command::Command0, Command::Command0,
Command::Command0, Command::Command0, Command::Command0, Command::Command0, Command::Command0,
Command::Command0, Command::Command0, Command::CommandDIV, Command::Command6, Command::Command4,
Command::Command4, Command::Command8, Command::Command8, Command::CommandEQU, Command::CommandNULL };
TestDriver::Test(L"15,506", L"1000000000 \x00F7 64488=", commands14, true, false);
} }
void CalculatorManagerTest::CalculatorManagerTestMemory() void CalculatorManagerTest::CalculatorManagerTestMemory()