diff --git a/src/CalcManager/Ratpack/support.cpp b/src/CalcManager/Ratpack/support.cpp index bcd31da2e..7a1c2be34 100644 --- a/src/CalcManager/Ratpack/support.cpp +++ b/src/CalcManager/Ratpack/support.cpp @@ -303,6 +303,12 @@ void intrat(_Inout_ PRAT* px, uint32_t radix, int32_t precision) DUPRAT(pret, *px); 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); destroyrat(pret); diff --git a/src/CalculatorUnitTests/CalculatorManagerTest.cpp b/src/CalculatorUnitTests/CalculatorManagerTest.cpp index aa1b0fe9a..73e83c0a1 100644 --- a/src/CalculatorUnitTests/CalculatorManagerTest.cpp +++ b/src/CalculatorUnitTests/CalculatorManagerTest.cpp @@ -752,6 +752,31 @@ namespace CalculatorManagerTest 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); + + 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()