Fix some code analysis warnings in CalcManager (#1074)

This commit is contained in:
Matt Cooley 2020-03-30 15:23:22 -07:00 committed by GitHub
parent cf735bbcf5
commit f552428d97
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
30 changed files with 225 additions and 219 deletions

View File

@ -210,7 +210,7 @@ bool CHistoryCollector::FOpndAddedToHistory()
// This is does the postfix to prefix translation of the input and adds the text to the history. Eg. doing 2 + 4 (sqrt), // This is does the postfix to prefix translation of the input and adds the text to the history. Eg. doing 2 + 4 (sqrt),
// this routine will ensure the last sqrt call unary operator, actually goes back in history and wraps 4 in sqrt(4) // this routine will ensure the last sqrt call unary operator, actually goes back in history and wraps 4 in sqrt(4)
// //
void CHistoryCollector::AddUnaryOpToHistory(int nOpCode, bool fInv, ANGLE_TYPE angletype) void CHistoryCollector::AddUnaryOpToHistory(int nOpCode, bool fInv, AngleType angletype)
{ {
int iCommandEnd; int iCommandEnd;
// When successfully applying a unary op, there should be an opnd already // When successfully applying a unary op, there should be an opnd already
@ -230,15 +230,15 @@ void CHistoryCollector::AddUnaryOpToHistory(int nOpCode, bool fInv, ANGLE_TYPE a
else else
{ {
CalculationManager::Command angleOpCode; CalculationManager::Command angleOpCode;
if (angletype == ANGLE_DEG) if (angletype == AngleType::Degrees)
{ {
angleOpCode = CalculationManager::Command::CommandDEG; angleOpCode = CalculationManager::Command::CommandDEG;
} }
else if (angletype == ANGLE_RAD) else if (angletype == AngleType::Radians)
{ {
angleOpCode = CalculationManager::Command::CommandRAD; angleOpCode = CalculationManager::Command::CommandRAD;
} }
else // (angletype == ANGLE_GRAD) else // (angletype == AngleType::Gradians)
{ {
angleOpCode = CalculationManager::Command::CommandGRAD; angleOpCode = CalculationManager::Command::CommandGRAD;
} }

View File

@ -460,7 +460,7 @@ namespace CalcEngine
return !(lhs < rhs); return !(lhs < rhs);
} }
wstring Rational::ToString(uint32_t radix, NUMOBJ_FMT fmt, int32_t precision) const wstring Rational::ToString(uint32_t radix, NumberFormat fmt, int32_t precision) const
{ {
PRAT rat = this->ToPRAT(); PRAT rat = this->ToPRAT();
wstring result{}; wstring result{};

View File

@ -147,7 +147,7 @@ Rational RationalMath::Abs(Rational const& rat)
return Rational{ Number{ 1, rat.P().Exp(), rat.P().Mantissa() }, Number{ 1, rat.Q().Exp(), rat.Q().Mantissa() } }; return Rational{ Number{ 1, rat.P().Exp(), rat.P().Mantissa() }, Number{ 1, rat.Q().Exp(), rat.Q().Mantissa() } };
} }
Rational RationalMath::Sin(Rational const& rat, ANGLE_TYPE angletype) Rational RationalMath::Sin(Rational const& rat, AngleType angletype)
{ {
PRAT prat = rat.ToPRAT(); PRAT prat = rat.ToPRAT();
@ -167,7 +167,7 @@ Rational RationalMath::Sin(Rational const& rat, ANGLE_TYPE angletype)
return result; return result;
} }
Rational RationalMath::Cos(Rational const& rat, ANGLE_TYPE angletype) Rational RationalMath::Cos(Rational const& rat, AngleType angletype)
{ {
PRAT prat = rat.ToPRAT(); PRAT prat = rat.ToPRAT();
@ -187,7 +187,7 @@ Rational RationalMath::Cos(Rational const& rat, ANGLE_TYPE angletype)
return result; return result;
} }
Rational RationalMath::Tan(Rational const& rat, ANGLE_TYPE angletype) Rational RationalMath::Tan(Rational const& rat, AngleType angletype)
{ {
PRAT prat = rat.ToPRAT(); PRAT prat = rat.ToPRAT();
@ -207,7 +207,7 @@ Rational RationalMath::Tan(Rational const& rat, ANGLE_TYPE angletype)
return result; return result;
} }
Rational RationalMath::ASin(Rational const& rat, ANGLE_TYPE angletype) Rational RationalMath::ASin(Rational const& rat, AngleType angletype)
{ {
PRAT prat = rat.ToPRAT(); PRAT prat = rat.ToPRAT();
@ -227,7 +227,7 @@ Rational RationalMath::ASin(Rational const& rat, ANGLE_TYPE angletype)
return result; return result;
} }
Rational RationalMath::ACos(Rational const& rat, ANGLE_TYPE angletype) Rational RationalMath::ACos(Rational const& rat, AngleType angletype)
{ {
PRAT prat = rat.ToPRAT(); PRAT prat = rat.ToPRAT();
@ -247,7 +247,7 @@ Rational RationalMath::ACos(Rational const& rat, ANGLE_TYPE angletype)
return result; return result;
} }
Rational RationalMath::ATan(Rational const& rat, ANGLE_TYPE angletype) Rational RationalMath::ATan(Rational const& rat, AngleType angletype)
{ {
PRAT prat = rat.ToPRAT(); PRAT prat = rat.ToPRAT();

View File

@ -73,7 +73,7 @@ CCalcEngine::CCalcEngine(
, m_bRecord(false) , m_bRecord(false)
, m_bSetCalcState(false) , m_bSetCalcState(false)
, m_input(DEFAULT_DEC_SEPARATOR) , m_input(DEFAULT_DEC_SEPARATOR)
, m_nFE(FMT_FLOAT) , m_nFE(NumberFormat::Float)
, m_memoryValue{ make_unique<Rational>() } , m_memoryValue{ make_unique<Rational>() }
, m_holdVal{} , m_holdVal{}
, m_currentVal{} , m_currentVal{}
@ -94,8 +94,8 @@ CCalcEngine::CCalcEngine(
, m_nPrecOp() , m_nPrecOp()
, m_precedenceOpCount(0) , m_precedenceOpCount(0)
, m_nLastCom(0) , m_nLastCom(0)
, m_angletype(ANGLE_DEG) , m_angletype(AngleType::Degrees)
, m_numwidth(QWORD_WIDTH) , m_numwidth(NUM_WIDTH::QWORD_WIDTH)
, m_HistoryCollector(pCalcDisplay, pHistoryDisplay, DEFAULT_DEC_SEPARATOR) , m_HistoryCollector(pCalcDisplay, pHistoryDisplay, DEFAULT_DEC_SEPARATOR)
, m_groupSeparator(DEFAULT_GRP_SEPARATOR) , m_groupSeparator(DEFAULT_GRP_SEPARATOR)
{ {
@ -105,7 +105,7 @@ CCalcEngine::CCalcEngine(
m_maxTrigonometricNum = RationalMath::Pow(10, 100); m_maxTrigonometricNum = RationalMath::Pow(10, 100);
SetRadixTypeAndNumWidth(DEC_RADIX, m_numwidth); SetRadixTypeAndNumWidth(RadixType::Decimal, m_numwidth);
SettingsChanged(); SettingsChanged();
DisplayNum(); DisplayNum();
} }
@ -128,10 +128,20 @@ void CCalcEngine::InitChopNumbers()
auto maxVal = m_chopNumbers[i] / 2; auto maxVal = m_chopNumbers[i] / 2;
maxVal = RationalMath::Integer(maxVal); maxVal = RationalMath::Integer(maxVal);
m_maxDecimalValueStrings[i] = maxVal.ToString(10, FMT_FLOAT, m_precision); m_maxDecimalValueStrings[i] = maxVal.ToString(10, NumberFormat::Float, m_precision);
} }
} }
CalcEngine::Rational CCalcEngine::GetChopNumber() const
{
return m_chopNumbers[static_cast<int>(m_numwidth)];
}
std::wstring CCalcEngine::GetMaxDecimalValueString() const
{
return m_maxDecimalValueStrings[static_cast<int>(m_numwidth)];
}
// Gets the number in memory for UI to keep it persisted and set it again to a different instance // Gets the number in memory for UI to keep it persisted and set it again to a different instance
// of CCalcEngine. Otherwise it will get destructed with the CalcEngine // of CCalcEngine. Otherwise it will get destructed with the CalcEngine
unique_ptr<Rational> CCalcEngine::PersistedMemObject() unique_ptr<Rational> CCalcEngine::PersistedMemObject()

View File

@ -177,7 +177,7 @@ void CCalcEngine::ProcessCommandWorker(OpCode wParam)
return; return;
} }
if (!m_input.TryAddDigit(iValue, m_radix, m_fIntegerMode, m_maxDecimalValueStrings[m_numwidth], m_dwWordBitWidth, m_cIntDigitsSav)) if (!m_input.TryAddDigit(iValue, m_radix, m_fIntegerMode, GetMaxDecimalValueString(), m_dwWordBitWidth, m_cIntDigitsSav))
{ {
HandleErrorCommand(wParam); HandleErrorCommand(wParam);
HandleMaxDigitsReached(); HandleMaxDigitsReached();
@ -619,7 +619,7 @@ void CCalcEngine::ProcessCommandWorker(OpCode wParam)
case IDM_OCT: case IDM_OCT:
case IDM_BIN: case IDM_BIN:
{ {
SetRadixTypeAndNumWidth((RADIX_TYPE)(wParam - IDM_HEX), (NUM_WIDTH)-1); SetRadixTypeAndNumWidth((RadixType)(wParam - IDM_HEX), (NUM_WIDTH)-1);
m_HistoryCollector.UpdateHistoryExpression(m_radix, m_precision); m_HistoryCollector.UpdateHistoryExpression(m_radix, m_precision);
break; break;
} }
@ -635,20 +635,20 @@ void CCalcEngine::ProcessCommandWorker(OpCode wParam)
} }
// Compat. mode BaseX: Qword, Dword, Word, Byte // Compat. mode BaseX: Qword, Dword, Word, Byte
SetRadixTypeAndNumWidth((RADIX_TYPE)-1, (NUM_WIDTH)(wParam - IDM_QWORD)); SetRadixTypeAndNumWidth((RadixType)-1, (NUM_WIDTH)(wParam - IDM_QWORD));
break; break;
case IDM_DEG: case IDM_DEG:
case IDM_RAD: case IDM_RAD:
case IDM_GRAD: case IDM_GRAD:
m_angletype = static_cast<ANGLE_TYPE>(wParam - IDM_DEG); m_angletype = static_cast<AngleType>(wParam - IDM_DEG);
break; break;
case IDC_SIGN: case IDC_SIGN:
{ {
if (m_bRecord) if (m_bRecord)
{ {
if (m_input.TryToggleSign(m_fIntegerMode, m_maxDecimalValueStrings[m_numwidth])) if (m_input.TryToggleSign(m_fIntegerMode, GetMaxDecimalValueString()))
{ {
DisplayNum(); DisplayNum();
} }
@ -766,7 +766,7 @@ void CCalcEngine::ProcessCommandWorker(OpCode wParam)
break; break;
case IDC_FE: case IDC_FE:
// Toggle exponential notation display. // Toggle exponential notation display.
m_nFE = NUMOBJ_FMT(!(int)m_nFE); m_nFE = NumberFormat(!(int)m_nFE);
DisplayNum(); DisplayNum();
break; break;
@ -961,7 +961,7 @@ static const std::unordered_map<int, FunctionNameElement> operatorStringTable =
{ IDC_MOD, { SIDS_MOD, L"", L"", L"", L"", L"", SIDS_PROGRAMMER_MOD } }, { IDC_MOD, { SIDS_MOD, L"", L"", L"", L"", L"", SIDS_PROGRAMMER_MOD } },
}; };
wstring_view CCalcEngine::OpCodeToUnaryString(int nOpCode, bool fInv, ANGLE_TYPE angletype) wstring_view CCalcEngine::OpCodeToUnaryString(int nOpCode, bool fInv, AngleType angletype)
{ {
// Try to lookup the ID in the UFNE table // Try to lookup the ID in the UFNE table
wstring ids = L""; wstring ids = L"";
@ -969,7 +969,7 @@ wstring_view CCalcEngine::OpCodeToUnaryString(int nOpCode, bool fInv, ANGLE_TYPE
if (auto pair = operatorStringTable.find(nOpCode); pair != operatorStringTable.end()) if (auto pair = operatorStringTable.find(nOpCode); pair != operatorStringTable.end())
{ {
const FunctionNameElement& element = pair->second; const FunctionNameElement& element = pair->second;
if (!element.hasAngleStrings || ANGLE_DEG == angletype) if (!element.hasAngleStrings || AngleType::Degrees == angletype)
{ {
if (fInv) if (fInv)
{ {
@ -981,7 +981,7 @@ wstring_view CCalcEngine::OpCodeToUnaryString(int nOpCode, bool fInv, ANGLE_TYPE
ids = element.degreeString; ids = element.degreeString;
} }
} }
else if (ANGLE_RAD == angletype) else if (AngleType::Radians == angletype)
{ {
if (fInv) if (fInv)
{ {
@ -992,7 +992,7 @@ wstring_view CCalcEngine::OpCodeToUnaryString(int nOpCode, bool fInv, ANGLE_TYPE
ids = element.radString; ids = element.radString;
} }
} }
else if (ANGLE_GRAD == angletype) else if (AngleType::Gradians == angletype)
{ {
if (fInv) if (fInv)
{ {
@ -1094,7 +1094,7 @@ wstring CCalcEngine::GetStringForDisplay(Rational const& rat, uint32_t radix)
if ((radix == 10) && fMsb) if ((radix == 10) && fMsb)
{ {
// If high bit is set, then get the decimal number in negative 2's complement form. // If high bit is set, then get the decimal number in negative 2's complement form.
tempRat = -((tempRat ^ m_chopNumbers[m_numwidth]) + 1); tempRat = -((tempRat ^ GetChopNumber()) + 1);
} }
result = tempRat.ToString(radix, m_nFE, m_precision); result = tempRat.ToString(radix, m_nFE, m_precision);

View File

@ -67,10 +67,10 @@ CalcEngine::Rational CCalcEngine::TruncateNumForIntMath(CalcEngine::Rational con
{ {
// if negative make positive by doing a twos complement // if negative make positive by doing a twos complement
result = -(result)-1; result = -(result)-1;
result ^= m_chopNumbers[m_numwidth]; result ^= GetChopNumber();
} }
result &= m_chopNumbers[m_numwidth]; result &= GetChopNumber();
return result; return result;
} }

View File

@ -42,7 +42,7 @@ CalcEngine::Rational CCalcEngine::SciCalcFunctions(CalcEngine::Rational const& r
} }
else else
{ {
result = rat ^ m_chopNumbers[m_numwidth]; result = rat ^ GetChopNumber();
} }
break; break;

View File

@ -29,11 +29,11 @@ CalcEngine::Rational CCalcEngine::DoOperation(int operation, CalcEngine::Rationa
break; break;
case IDC_NAND: case IDC_NAND:
result = (result & rhs) ^ m_chopNumbers[m_numwidth]; result = (result & rhs) ^ GetChopNumber();
break; break;
case IDC_NOR: case IDC_NOR:
result = (result | rhs) ^ m_chopNumbers[m_numwidth]; result = (result | rhs) ^ GetChopNumber();
break; break;
case IDC_RSHF: case IDC_RSHF:
@ -53,10 +53,10 @@ CalcEngine::Rational CCalcEngine::DoOperation(int operation, CalcEngine::Rationa
{ {
result = Integer(result); result = Integer(result);
auto tempRat = m_chopNumbers[m_numwidth] >> holdVal; auto tempRat = GetChopNumber() >> holdVal;
tempRat = Integer(tempRat); tempRat = Integer(tempRat);
result |= tempRat ^ m_chopNumbers[m_numwidth]; result |= tempRat ^ GetChopNumber();
} }
break; break;
} }
@ -105,7 +105,7 @@ CalcEngine::Rational CCalcEngine::DoOperation(int operation, CalcEngine::Rationa
if (fMsb) if (fMsb)
{ {
result = (rhs ^ m_chopNumbers[m_numwidth]) + 1; result = (rhs ^ GetChopNumber()) + 1;
iNumeratorSign = -1; iNumeratorSign = -1;
} }
@ -115,7 +115,7 @@ CalcEngine::Rational CCalcEngine::DoOperation(int operation, CalcEngine::Rationa
if (fMsb) if (fMsb)
{ {
temp = (temp ^ m_chopNumbers[m_numwidth]) + 1; temp = (temp ^ GetChopNumber()) + 1;
iDenominatorSign = -1; iDenominatorSign = -1;
} }

View File

@ -9,7 +9,7 @@ using namespace std;
// To be called when either the radix or num width changes. You can use -1 in either of these values to mean // To be called when either the radix or num width changes. You can use -1 in either of these values to mean
// dont change that. // dont change that.
void CCalcEngine::SetRadixTypeAndNumWidth(RADIX_TYPE radixtype, NUM_WIDTH numwidth) void CCalcEngine::SetRadixTypeAndNumWidth(RadixType radixtype, NUM_WIDTH numwidth)
{ {
// When in integer mode, the number is represented in 2's complement form. When a bit width is changing, we can // When in integer mode, the number is represented in 2's complement form. When a bit width is changing, we can
// change the number representation back to sign, abs num form in ratpak. Soon when display sees this, it will // change the number representation back to sign, abs num form in ratpak. Soon when display sees this, it will
@ -24,19 +24,19 @@ void CCalcEngine::SetRadixTypeAndNumWidth(RADIX_TYPE radixtype, NUM_WIDTH numwid
if (fMsb) if (fMsb)
{ {
// If high bit is set, then get the decimal number in -ve 2'scompl form. // If high bit is set, then get the decimal number in -ve 2'scompl form.
auto tempResult = m_currentVal ^ m_chopNumbers[m_numwidth]; auto tempResult = m_currentVal ^ GetChopNumber();
m_currentVal = -(tempResult + 1); m_currentVal = -(tempResult + 1);
} }
} }
if (radixtype >= HEX_RADIX && radixtype <= BIN_RADIX) if (radixtype >= RadixType::Hex && radixtype <= RadixType::Binary)
{ {
m_radix = NRadixFromRadixType(radixtype); m_radix = NRadixFromRadixType(radixtype);
// radixtype is not even saved // radixtype is not even saved
} }
if (numwidth >= QWORD_WIDTH && numwidth <= BYTE_WIDTH) if (numwidth >= NUM_WIDTH::QWORD_WIDTH && numwidth <= NUM_WIDTH::BYTE_WIDTH)
{ {
m_numwidth = numwidth; m_numwidth = numwidth;
m_dwWordBitWidth = DwWordBitWidthFromeNumWidth(numwidth); m_dwWordBitWidth = DwWordBitWidthFromeNumWidth(numwidth);
@ -50,29 +50,36 @@ void CCalcEngine::SetRadixTypeAndNumWidth(RADIX_TYPE radixtype, NUM_WIDTH numwid
DisplayNum(); DisplayNum();
} }
int32_t CCalcEngine::DwWordBitWidthFromeNumWidth(NUM_WIDTH /*numwidth*/) int32_t CCalcEngine::DwWordBitWidthFromeNumWidth(NUM_WIDTH numwidth)
{ {
static constexpr int nBitMax[] = { 64, 32, 16, 8 }; switch (numwidth)
int32_t wmax = nBitMax[0];
if (m_numwidth >= 0 && (size_t)m_numwidth < size(nBitMax))
{ {
wmax = nBitMax[m_numwidth]; case NUM_WIDTH::DWORD_WIDTH:
return 32;
case NUM_WIDTH::WORD_WIDTH:
return 16;
case NUM_WIDTH::BYTE_WIDTH:
return 8;
case NUM_WIDTH::QWORD_WIDTH:
default:
return 64;
} }
return wmax;
} }
uint32_t CCalcEngine::NRadixFromRadixType(RADIX_TYPE radixtype) uint32_t CCalcEngine::NRadixFromRadixType(RadixType radixtype)
{ {
static constexpr uint32_t rgnRadish[4] = { 16, 10, 8, 2 }; /* Number bases in the same order as radixtype */ switch (radixtype)
uint32_t radix = 10;
// convert special bases into symbolic values
if (radixtype >= 0 && (size_t)radixtype < size(rgnRadish))
{ {
radix = rgnRadish[radixtype]; case RadixType::Hex:
return 16;
case RadixType::Octal:
return 8;
case RadixType::Binary:
return 2;
case RadixType::Decimal:
default:
return 10;
} }
return radix;
} }
// Toggles a given bit into the number representation. returns true if it changed it actually. // Toggles a given bit into the number representation. returns true if it changed it actually.
@ -141,7 +148,7 @@ void CCalcEngine::UpdateMaxIntDigits()
// if in integer mode you still have to honor the max digits you can enter based on bit width // if in integer mode you still have to honor the max digits you can enter based on bit width
if (m_fIntegerMode) if (m_fIntegerMode)
{ {
m_cIntDigitsSav = static_cast<int>(m_maxDecimalValueStrings[m_numwidth].length()) - 1; m_cIntDigitsSav = static_cast<int>(GetMaxDecimalValueString().length()) - 1;
// This is the max digits you can enter a decimal in fixed width mode aka integer mode -1. The last digit // This is the max digits you can enter a decimal in fixed width mode aka integer mode -1. The last digit
// has to be checked separately // has to be checked separately
} }

View File

@ -7,12 +7,6 @@
namespace CalculationManager namespace CalculationManager
{ {
enum CALCULATOR_MODE
{
CM_STD = 0,
CM_SCI,
};
struct HISTORYITEMVECTOR struct HISTORYITEMVECTOR
{ {
std::shared_ptr<std::vector<std::pair<std::wstring, int>>> spTokens; std::shared_ptr<std::vector<std::pair<std::wstring, int>>> spTokens;

View File

@ -33,6 +33,7 @@ namespace CalculationManager
, m_savedDegreeMode(Command::CommandDEG) , m_savedDegreeMode(Command::CommandDEG)
, m_pStdHistory(new CalculatorHistory(MAX_HISTORY_ITEMS)) , m_pStdHistory(new CalculatorHistory(MAX_HISTORY_ITEMS))
, m_pSciHistory(new CalculatorHistory(MAX_HISTORY_ITEMS)) , m_pSciHistory(new CalculatorHistory(MAX_HISTORY_ITEMS))
, m_pHistory(nullptr)
{ {
CCalcEngine::InitialOneTimeOnlySetup(*m_resourceProvider); CCalcEngine::InitialOneTimeOnlySetup(*m_resourceProvider);
} }
@ -551,9 +552,9 @@ namespace CalculationManager
return m_pHistory->GetHistory(); return m_pHistory->GetHistory();
} }
vector<shared_ptr<HISTORYITEM>> const& CalculatorManager::GetHistoryItems(_In_ CALCULATOR_MODE mode) vector<shared_ptr<HISTORYITEM>> const& CalculatorManager::GetHistoryItems(_In_ CalculatorMode mode)
{ {
return (mode == CM_STD) ? m_pStdHistory->GetHistory() : m_pSciHistory->GetHistory(); return (mode == CalculatorMode::Standard) ? m_pStdHistory->GetHistory() : m_pSciHistory->GetHistory();
} }
shared_ptr<HISTORYITEM> const& CalculatorManager::GetHistoryItem(_In_ unsigned int uIdx) shared_ptr<HISTORYITEM> const& CalculatorManager::GetHistoryItem(_In_ unsigned int uIdx)
@ -576,20 +577,20 @@ namespace CalculationManager
m_pHistory->ClearHistory(); m_pHistory->ClearHistory();
} }
void CalculatorManager::SetRadix(RADIX_TYPE iRadixType) void CalculatorManager::SetRadix(RadixType iRadixType)
{ {
switch (iRadixType) switch (iRadixType)
{ {
case RADIX_TYPE::HEX_RADIX: case RadixType::Hex:
m_currentCalculatorEngine->ProcessCommand(IDC_HEX); m_currentCalculatorEngine->ProcessCommand(IDC_HEX);
break; break;
case RADIX_TYPE::DEC_RADIX: case RadixType::Decimal:
m_currentCalculatorEngine->ProcessCommand(IDC_DEC); m_currentCalculatorEngine->ProcessCommand(IDC_DEC);
break; break;
case RADIX_TYPE::OCT_RADIX: case RadixType::Octal:
m_currentCalculatorEngine->ProcessCommand(IDC_OCT); m_currentCalculatorEngine->ProcessCommand(IDC_OCT);
break; break;
case RADIX_TYPE::BIN_RADIX: case RadixType::Binary:
m_currentCalculatorEngine->ProcessCommand(IDC_BIN); m_currentCalculatorEngine->ProcessCommand(IDC_BIN);
break; break;
default: default:
@ -623,16 +624,16 @@ namespace CalculationManager
return m_currentDegreeMode; return m_currentDegreeMode;
} }
void CalculatorManager::SetHistory(_In_ CALCULATOR_MODE eMode, _In_ vector<shared_ptr<HISTORYITEM>> const& history) void CalculatorManager::SetHistory(_In_ CalculatorMode eMode, _In_ vector<shared_ptr<HISTORYITEM>> const& history)
{ {
CalculatorHistory* pHistory = nullptr; CalculatorHistory* pHistory = nullptr;
switch (eMode) switch (eMode)
{ {
case CM_STD: case CalculatorMode::Standard:
pHistory = m_pStdHistory.get(); pHistory = m_pStdHistory.get();
break; break;
case CM_SCI: case CalculatorMode::Scientific:
pHistory = m_pSciHistory.get(); pHistory = m_pSciHistory.get();
break; break;
} }

View File

@ -15,9 +15,8 @@ namespace CalculationManager
enum class CalculatorMode enum class CalculatorMode
{ {
StandardMode, Standard = 0,
ScientificMode, Scientific,
ProgrammerMode,
}; };
enum class CalculatorPrecision enum class CalculatorPrecision
@ -117,7 +116,7 @@ namespace CalculationManager
{ {
return m_savedCommands; return m_savedCommands;
} }
void SetRadix(RADIX_TYPE iRadixType); void SetRadix(RadixType iRadixType);
void SetMemorizedNumbersString(); void SetMemorizedNumbersString();
std::wstring GetResultForRadix(uint32_t radix, int32_t precision, bool groupDigitsPerRadix); std::wstring GetResultForRadix(uint32_t radix, int32_t precision, bool groupDigitsPerRadix);
void SetPrecision(int32_t precision); void SetPrecision(int32_t precision);
@ -125,7 +124,7 @@ namespace CalculationManager
wchar_t DecimalSeparator(); wchar_t DecimalSeparator();
std::vector<std::shared_ptr<HISTORYITEM>> const& GetHistoryItems(); std::vector<std::shared_ptr<HISTORYITEM>> const& GetHistoryItems();
std::vector<std::shared_ptr<HISTORYITEM>> const& GetHistoryItems(_In_ CalculationManager::CALCULATOR_MODE mode); std::vector<std::shared_ptr<HISTORYITEM>> const& GetHistoryItems(_In_ CalculatorMode mode);
std::shared_ptr<HISTORYITEM> const& GetHistoryItem(_In_ unsigned int uIdx); std::shared_ptr<HISTORYITEM> const& GetHistoryItem(_In_ unsigned int uIdx);
bool RemoveHistoryItem(_In_ unsigned int uIdx); bool RemoveHistoryItem(_In_ unsigned int uIdx);
void ClearHistory(); void ClearHistory();
@ -134,7 +133,7 @@ namespace CalculationManager
return m_pHistory->MaxHistorySize(); return m_pHistory->MaxHistorySize();
} }
CalculationManager::Command GetCurrentDegreeMode(); CalculationManager::Command GetCurrentDegreeMode();
void SetHistory(_In_ CALCULATOR_MODE eMode, _In_ std::vector<std::shared_ptr<HISTORYITEM>> const& history); void SetHistory(_In_ CalculatorMode eMode, _In_ std::vector<std::shared_ptr<HISTORYITEM>> const& history);
void SetInHistoryItemLoadMode(_In_ bool isHistoryItemLoadMode); void SetInHistoryItemLoadMode(_In_ bool isHistoryItemLoadMode);
}; };
} }

View File

@ -277,7 +277,7 @@ wstring COpndCommand::GetString(uint32_t radix, int32_t precision)
{ {
if (m_fInitialized) if (m_fInitialized)
{ {
return m_value.ToString(radix, eNUMOBJ_FMT::FMT_FLOAT, precision); return m_value.ToString(radix, NumberFormat::Float, precision);
} }
return wstring{}; return wstring{};

View File

@ -31,14 +31,13 @@
// The real exports follows later // The real exports follows later
// This is expected to be in same order as IDM_QWORD, IDM_DWORD etc. // This is expected to be in same order as IDM_QWORD, IDM_DWORD etc.
enum eNUM_WIDTH enum class NUM_WIDTH
{ {
QWORD_WIDTH, // Number width of 64 bits mode (default) QWORD_WIDTH, // Number width of 64 bits mode (default)
DWORD_WIDTH, // Number width of 32 bits mode DWORD_WIDTH, // Number width of 32 bits mode
WORD_WIDTH, // Number width of 16 bits mode WORD_WIDTH, // Number width of 16 bits mode
BYTE_WIDTH // Number width of 16 bits mode BYTE_WIDTH // Number width of 16 bits mode
}; };
typedef enum eNUM_WIDTH NUM_WIDTH;
static constexpr size_t NUM_WIDTH_LENGTH = 4; static constexpr size_t NUM_WIDTH_LENGTH = 4;
namespace CalculationManager namespace CalculationManager
@ -106,7 +105,7 @@ public:
{ {
return GetString(IdStrFromCmdId(nOpCode)); return GetString(IdStrFromCmdId(nOpCode));
} }
static std::wstring_view OpCodeToUnaryString(int nOpCode, bool fInv, ANGLE_TYPE angletype); static std::wstring_view OpCodeToUnaryString(int nOpCode, bool fInv, AngleType angletype);
static std::wstring_view OpCodeToBinaryString(int nOpCode, bool isIntegerMode); static std::wstring_view OpCodeToBinaryString(int nOpCode, bool isIntegerMode);
private: private:
@ -117,11 +116,11 @@ private:
int m_nOpCode; /* ID value of operation. */ int m_nOpCode; /* ID value of operation. */
int m_nPrevOpCode; // opcode which computed the number in m_currentVal. 0 if it is already bracketed or plain number or int m_nPrevOpCode; // opcode which computed the number in m_currentVal. 0 if it is already bracketed or plain number or
// if it hasn't yet been computed // if it hasn't yet been computed
bool m_bChangeOp; /* Flag for changing operation. */ bool m_bChangeOp; // Flag for changing operation
bool m_bRecord; // Global mode: recording or displaying bool m_bRecord; // Global mode: recording or displaying
bool m_bSetCalcState; // Flag for setting the engine result state bool m_bSetCalcState; // Flag for setting the engine result state
CalcEngine::CalcInput m_input; // Global calc input object for decimal strings CalcEngine::CalcInput m_input; // Global calc input object for decimal strings
eNUMOBJ_FMT m_nFE; /* Scientific notation conversion flag. */ NumberFormat m_nFE; // Scientific notation conversion flag
CalcEngine::Rational m_maxTrigonometricNum; CalcEngine::Rational m_maxTrigonometricNum;
std::unique_ptr<CalcEngine::Rational> m_memoryValue; // Current memory value. std::unique_ptr<CalcEngine::Rational> m_memoryValue; // Current memory value.
@ -148,7 +147,7 @@ private:
std::array<int, MAXPRECDEPTH> m_nPrecOp; /* Holding array for precedence operations. */ std::array<int, MAXPRECDEPTH> m_nPrecOp; /* Holding array for precedence operations. */
size_t m_precedenceOpCount; /* Current number of precedence ops in holding. */ size_t m_precedenceOpCount; /* Current number of precedence ops in holding. */
int m_nLastCom; // Last command entered. int m_nLastCom; // Last command entered.
ANGLE_TYPE m_angletype; // Current Angle type when in dec mode. one of deg, rad or grad AngleType m_angletype; // Current Angle type when in dec mode. one of deg, rad or grad
NUM_WIDTH m_numwidth; // one of qword, dword, word or byte mode. NUM_WIDTH m_numwidth; // one of qword, dword, word or byte mode.
int32_t m_dwWordBitWidth; // # of bits in currently selected word size int32_t m_dwWordBitWidth; // # of bits in currently selected word size
@ -179,15 +178,17 @@ private:
CalcEngine::Rational TruncateNumForIntMath(CalcEngine::Rational const& rat); CalcEngine::Rational TruncateNumForIntMath(CalcEngine::Rational const& rat);
CalcEngine::Rational SciCalcFunctions(CalcEngine::Rational const& rat, uint32_t op); CalcEngine::Rational SciCalcFunctions(CalcEngine::Rational const& rat, uint32_t op);
CalcEngine::Rational DoOperation(int operation, CalcEngine::Rational const& lhs, CalcEngine::Rational const& rhs); CalcEngine::Rational DoOperation(int operation, CalcEngine::Rational const& lhs, CalcEngine::Rational const& rhs);
void SetRadixTypeAndNumWidth(RADIX_TYPE radixtype, NUM_WIDTH numwidth); void SetRadixTypeAndNumWidth(RadixType radixtype, NUM_WIDTH numwidth);
int32_t DwWordBitWidthFromeNumWidth(NUM_WIDTH numwidth); int32_t DwWordBitWidthFromeNumWidth(NUM_WIDTH numwidth);
uint32_t NRadixFromRadixType(RADIX_TYPE radixtype); uint32_t NRadixFromRadixType(RadixType radixtype);
double GenerateRandomNumber(); double GenerateRandomNumber();
bool TryToggleBit(CalcEngine::Rational& rat, uint32_t wbitno); bool TryToggleBit(CalcEngine::Rational& rat, uint32_t wbitno);
void CheckAndAddLastBinOpToHistory(bool addToHistory = true); void CheckAndAddLastBinOpToHistory(bool addToHistory = true);
void InitChopNumbers(); void InitChopNumbers();
CalcEngine::Rational GetChopNumber() const;
std::wstring GetMaxDecimalValueString() const;
static void LoadEngineStrings(CalculationManager::IResourceProvider& resourceProvider); static void LoadEngineStrings(CalculationManager::IResourceProvider& resourceProvider);
static int IdStrFromCmdId(int id) static int IdStrFromCmdId(int id)

View File

@ -23,7 +23,7 @@ public:
void RemoveLastOpndFromHistory(); void RemoveLastOpndFromHistory();
void AddBinOpToHistory(int nOpCode, bool isIntgerMode, bool fNoRepetition = true); void AddBinOpToHistory(int nOpCode, bool isIntgerMode, bool fNoRepetition = true);
void ChangeLastBinOp(int nOpCode, bool fPrecInvToHigher, bool isIntgerMode); void ChangeLastBinOp(int nOpCode, bool fPrecInvToHigher, bool isIntgerMode);
void AddUnaryOpToHistory(int nOpCode, bool fInv, ANGLE_TYPE angletype); void AddUnaryOpToHistory(int nOpCode, bool fInv, AngleType angletype);
void AddOpenBraceToHistory(); void AddOpenBraceToHistory();
void AddCloseBraceToHistory(); void AddCloseBraceToHistory();
void PushLastOpndStart(int ichOpndStart = -1); void PushLastOpndStart(int ichOpndStart = -1);

View File

@ -4,11 +4,10 @@
#pragma once #pragma once
// This is expected to be in same order as IDM_HEX, IDM_DEC, IDM_OCT, IDM_BIN // This is expected to be in same order as IDM_HEX, IDM_DEC, IDM_OCT, IDM_BIN
enum eRADIX_TYPE enum class RadixType
{ {
HEX_RADIX, Hex,
DEC_RADIX, Decimal,
OCT_RADIX, Octal,
BIN_RADIX Binary
}; };
typedef enum eRADIX_TYPE RADIX_TYPE;

View File

@ -64,7 +64,7 @@ namespace CalcEngine
friend bool operator<=(Rational const& lhs, Rational const& rhs); friend bool operator<=(Rational const& lhs, Rational const& rhs);
friend bool operator>=(Rational const& lhs, Rational const& rhs); friend bool operator>=(Rational const& lhs, Rational const& rhs);
std::wstring ToString(uint32_t radix, NUMOBJ_FMT format, int32_t precision) const; std::wstring ToString(uint32_t radix, NumberFormat format, int32_t precision) const;
uint64_t ToUInt64_t() const; uint64_t ToUInt64_t() const;
private: private:

View File

@ -22,12 +22,12 @@ namespace CalcEngine::RationalMath
Rational Invert(Rational const& rat); Rational Invert(Rational const& rat);
Rational Abs(Rational const& rat); Rational Abs(Rational const& rat);
Rational Sin(Rational const& rat, ANGLE_TYPE angletype); Rational Sin(Rational const& rat, AngleType angletype);
Rational Cos(Rational const& rat, ANGLE_TYPE angletype); Rational Cos(Rational const& rat, AngleType angletype);
Rational Tan(Rational const& rat, ANGLE_TYPE angletype); Rational Tan(Rational const& rat, AngleType angletype);
Rational ASin(Rational const& rat, ANGLE_TYPE angletype); Rational ASin(Rational const& rat, AngleType angletype);
Rational ACos(Rational const& rat, ANGLE_TYPE angletype); Rational ACos(Rational const& rat, AngleType angletype);
Rational ATan(Rational const& rat, ANGLE_TYPE angletype); Rational ATan(Rational const& rat, AngleType angletype);
Rational Sinh(Rational const& rat); Rational Sinh(Rational const& rat);
Rational Cosh(Rational const& rat); Rational Cosh(Rational const& rat);

View File

@ -1063,27 +1063,27 @@ bool stripzeroesnum(_Inout_ PNUMBER pnum, int32_t starting)
// FUNCTION: NumberToString // FUNCTION: NumberToString
// //
// ARGUMENTS: number representation // ARGUMENTS: number representation
// fmt, one of FMT_FLOAT FMT_SCIENTIFIC or // fmt, one of NumberFormat::Float, NumberFormat::Scientific or
// FMT_ENGINEERING // NumberFormat::Engineering
// integer radix and int32_t precision value // integer radix and int32_t precision value
// //
// RETURN: String representation of number. // RETURN: String representation of number.
// //
// DESCRIPTION: Converts a number to it's string // DESCRIPTION: Converts a number to its string
// representation. // representation.
// //
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
wstring NumberToString(_Inout_ PNUMBER& pnum, int format, uint32_t radix, int32_t precision) wstring NumberToString(_Inout_ PNUMBER& pnum, NumberFormat format, uint32_t radix, int32_t precision)
{ {
stripzeroesnum(pnum, precision + 2); stripzeroesnum(pnum, precision + 2);
int32_t length = pnum->cdigit; int32_t length = pnum->cdigit;
int32_t exponent = pnum->exp + length; // Actual number of digits to the left of decimal int32_t exponent = pnum->exp + length; // Actual number of digits to the left of decimal
int32_t oldFormat = format; NumberFormat oldFormat = format;
if (exponent > precision && format == FMT_FLOAT) if (exponent > precision && format == NumberFormat::Float)
{ {
// Force scientific mode to prevent user from assuming 33rd digit is exact. // Force scientific mode to prevent user from assuming 33rd digit is exact.
format = FMT_SCIENTIFIC; format = NumberFormat::Scientific;
} }
// Make length small enough to fit in pret. // Make length small enough to fit in pret.
@ -1103,7 +1103,7 @@ wstring NumberToString(_Inout_ PNUMBER& pnum, int format, uint32_t radix, int32_
divnum(&round, num_two, radix, precision); divnum(&round, num_two, radix, precision);
// Make round number exponent one below the LSD for the number. // Make round number exponent one below the LSD for the number.
if (exponent > 0 || format == FMT_FLOAT) if (exponent > 0 || format == NumberFormat::Float)
{ {
round->exp = pnum->exp + pnum->cdigit - round->cdigit - precision; round->exp = pnum->exp + pnum->cdigit - round->cdigit - precision;
} }
@ -1116,7 +1116,7 @@ wstring NumberToString(_Inout_ PNUMBER& pnum, int format, uint32_t radix, int32_
round->sign = pnum->sign; round->sign = pnum->sign;
} }
if (format == FMT_FLOAT) if (format == NumberFormat::Float)
{ {
// Figure out if the exponent will fill more space than the non-exponent field. // Figure out if the exponent will fill more space than the non-exponent field.
if ((length - exponent > precision) || (exponent > precision + 3)) if ((length - exponent > precision) || (exponent > precision + 3))
@ -1130,7 +1130,7 @@ wstring NumberToString(_Inout_ PNUMBER& pnum, int format, uint32_t radix, int32_
{ {
// Case where too many zeros are to the right or left of the // Case where too many zeros are to the right or left of the
// decimal pt. And we are forced to switch to scientific form. // decimal pt. And we are forced to switch to scientific form.
format = FMT_SCIENTIFIC; format = NumberFormat::Scientific;
} }
} }
else if (length + abs(exponent) < precision && round) else if (length + abs(exponent) < precision && round)
@ -1163,13 +1163,13 @@ wstring NumberToString(_Inout_ PNUMBER& pnum, int format, uint32_t radix, int32_
int32_t eout = exponent - 1; // Displayed exponent. int32_t eout = exponent - 1; // Displayed exponent.
MANTTYPE* pmant = pnum->mant + pnum->cdigit - 1; MANTTYPE* pmant = pnum->mant + pnum->cdigit - 1;
// Case where too many digits are to the left of the decimal or // Case where too many digits are to the left of the decimal or
// FMT_SCIENTIFIC or FMT_ENGINEERING was specified. // NumberFormat::Scientific or NumberFormat::Engineering was specified.
if ((format == FMT_SCIENTIFIC) || (format == FMT_ENGINEERING)) if ((format == NumberFormat::Scientific) || (format == NumberFormat::Engineering))
{ {
useSciForm = true; useSciForm = true;
if (eout != 0) if (eout != 0)
{ {
if (format == FMT_ENGINEERING) if (format == NumberFormat::Engineering)
{ {
exponent = (eout % 3); exponent = (eout % 3);
eout -= exponent; eout -= exponent;
@ -1270,7 +1270,7 @@ wstring NumberToString(_Inout_ PNUMBER& pnum, int format, uint32_t radix, int32_
// ARGUMENTS: // ARGUMENTS:
// PRAT *representation of a number. // PRAT *representation of a number.
// i32 representation of base to dump to screen. // i32 representation of base to dump to screen.
// fmt, one of FMT_FLOAT FMT_SCIENTIFIC or FMT_ENGINEERING // fmt, one of NumberFormat::Float, NumberFormat::Scientific, or NumberFormat::Engineering
// precision uint32_t // precision uint32_t
// //
// RETURN: string // RETURN: string
@ -1283,7 +1283,7 @@ wstring NumberToString(_Inout_ PNUMBER& pnum, int format, uint32_t radix, int32_
// why a pointer to the rational is passed in. // why a pointer to the rational is passed in.
// //
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
wstring RatToString(_Inout_ PRAT& prat, int format, uint32_t radix, int32_t precision) wstring RatToString(_Inout_ PRAT& prat, NumberFormat format, uint32_t radix, int32_t precision)
{ {
PNUMBER p = RatToNumber(prat, radix, precision); PNUMBER p = RatToNumber(prat, radix, precision);

View File

@ -17,17 +17,17 @@
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
#include "ratpak.h" #include "ratpak.h"
void ascalerat(_Inout_ PRAT* pa, ANGLE_TYPE angletype, int32_t precision) void ascalerat(_Inout_ PRAT* pa, AngleType angletype, int32_t precision)
{ {
switch (angletype) switch (angletype)
{ {
case ANGLE_RAD: case AngleType::Radians:
break; break;
case ANGLE_DEG: case AngleType::Degrees:
divrat(pa, two_pi, precision); divrat(pa, two_pi, precision);
mulrat(pa, rat_360, precision); mulrat(pa, rat_360, precision);
break; break;
case ANGLE_GRAD: case AngleType::Gradians:
divrat(pa, two_pi, precision); divrat(pa, two_pi, precision);
mulrat(pa, rat_400, precision); mulrat(pa, rat_400, precision);
break; break;
@ -76,7 +76,7 @@ void _asinrat(PRAT* px, int32_t precision)
DESTROYTAYLOR(); DESTROYTAYLOR();
} }
void asinanglerat(_Inout_ PRAT* pa, ANGLE_TYPE angletype, uint32_t radix, int32_t precision) void asinanglerat(_Inout_ PRAT* pa, AngleType angletype, uint32_t radix, int32_t precision)
{ {
asinrat(pa, radix, precision); asinrat(pa, radix, precision);
@ -164,7 +164,7 @@ void asinrat(_Inout_ PRAT* px, uint32_t radix, int32_t precision)
// //
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void acosanglerat(_Inout_ PRAT* pa, ANGLE_TYPE angletype, uint32_t radix, int32_t precision) void acosanglerat(_Inout_ PRAT* pa, AngleType angletype, uint32_t radix, int32_t precision)
{ {
acosrat(pa, radix, precision); acosrat(pa, radix, precision);
@ -249,7 +249,7 @@ void acosrat(_Inout_ PRAT* px, uint32_t radix, int32_t precision)
// //
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void atananglerat(_Inout_ PRAT* pa, ANGLE_TYPE angletype, uint32_t radix, int32_t precision) void atananglerat(_Inout_ PRAT* pa, AngleType angletype, uint32_t radix, int32_t precision)
{ {
atanrat(pa, radix, precision); atanrat(pa, radix, precision);

View File

@ -31,25 +31,20 @@ static constexpr uint32_t BASEX = 0x80000000; // Internal radix used in calculat
typedef uint32_t MANTTYPE; typedef uint32_t MANTTYPE;
typedef uint64_t TWO_MANTTYPE; typedef uint64_t TWO_MANTTYPE;
enum eNUMOBJ_FMT enum class NumberFormat
{ {
FMT_FLOAT, // returns floating point, or exponential if number is too big Float, // returns floating point, or exponential if number is too big
FMT_SCIENTIFIC, // always returns scientific notation Scientific, // always returns scientific notation
FMT_ENGINEERING // always returns engineering notation such that exponent is a multiple of 3 Engineering // always returns engineering notation such that exponent is a multiple of 3
}; };
enum eANGLE_TYPE enum class AngleType
{ {
ANGLE_DEG, // Calculate trig using 360 degrees per revolution Degrees, // Calculate trig using 360 degrees per revolution
ANGLE_RAD, // Calculate trig using 2 pi radians per revolution Radians, // Calculate trig using 2 pi radians per revolution
ANGLE_GRAD // Calculate trig using 400 gradients per revolution Gradians // Calculate trig using 400 gradians per revolution
}; };
typedef enum eNUMOBJ_FMT NUMOBJ_FMT;
typedef enum eANGLE_TYPE ANGLE_TYPE;
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// //
// NUMBER type is a representation of a generic sized generic radix number // NUMBER type is a representation of a generic sized generic radix number
@ -341,10 +336,10 @@ extern bool equnum(_In_ PNUMBER a, _In_ PNUMBER b); // returns true of a == b
extern bool lessnum(_In_ PNUMBER a, _In_ PNUMBER b); // returns true of a < b extern bool lessnum(_In_ PNUMBER a, _In_ PNUMBER b); // returns true of a < b
extern bool zernum(_In_ PNUMBER a); // returns true of a == 0 extern bool zernum(_In_ PNUMBER a); // returns true of a == 0
extern bool zerrat(_In_ PRAT a); // returns true if a == 0/q extern bool zerrat(_In_ PRAT a); // returns true if a == 0/q
extern std::wstring NumberToString(_Inout_ PNUMBER& pnum, int format, uint32_t radix, int32_t precision); extern std::wstring NumberToString(_Inout_ PNUMBER& pnum, NumberFormat format, uint32_t radix, int32_t precision);
// returns a text representation of a PRAT // returns a text representation of a PRAT
extern std::wstring RatToString(_Inout_ PRAT& prat, int format, uint32_t radix, int32_t precision); extern std::wstring RatToString(_Inout_ PRAT& prat, NumberFormat format, uint32_t radix, int32_t precision);
// converts a PRAT into a PNUMBER // converts a PRAT into a PNUMBER
extern PNUMBER RatToNumber(_In_ PRAT prat, uint32_t radix, int32_t precision); extern PNUMBER RatToNumber(_In_ PRAT prat, uint32_t radix, int32_t precision);
// flattens a PRAT by converting it to a PNUMBER and back to a PRAT // flattens a PRAT by converting it to a PNUMBER and back to a PRAT
@ -376,7 +371,7 @@ extern PRAT _createrat(void);
// returns a new rat structure with the acos of x->p/x->q taking into account // returns a new rat structure with the acos of x->p/x->q taking into account
// angle type // angle type
extern void acosanglerat(_Inout_ PRAT* px, ANGLE_TYPE angletype, uint32_t radix, int32_t precision); extern void acosanglerat(_Inout_ PRAT* px, AngleType angletype, uint32_t radix, int32_t precision);
// returns a new rat structure with the acosh of x->p/x->q // returns a new rat structure with the acosh of x->p/x->q
extern void acoshrat(_Inout_ PRAT* px, uint32_t radix, int32_t precision); extern void acoshrat(_Inout_ PRAT* px, uint32_t radix, int32_t precision);
@ -386,7 +381,7 @@ extern void acosrat(_Inout_ PRAT* px, uint32_t radix, int32_t precision);
// returns a new rat structure with the asin of x->p/x->q taking into account // returns a new rat structure with the asin of x->p/x->q taking into account
// angle type // angle type
extern void asinanglerat(_Inout_ PRAT* px, ANGLE_TYPE angletype, uint32_t radix, int32_t precision); extern void asinanglerat(_Inout_ PRAT* px, AngleType angletype, uint32_t radix, int32_t precision);
extern void asinhrat(_Inout_ PRAT* px, uint32_t radix, int32_t precision); extern void asinhrat(_Inout_ PRAT* px, uint32_t radix, int32_t precision);
// returns a new rat structure with the asinh of x->p/x->q // returns a new rat structure with the asinh of x->p/x->q
@ -396,7 +391,7 @@ extern void asinrat(_Inout_ PRAT* px, uint32_t radix, int32_t precision);
// returns a new rat structure with the atan of x->p/x->q taking into account // returns a new rat structure with the atan of x->p/x->q taking into account
// angle type // angle type
extern void atananglerat(_Inout_ PRAT* px, ANGLE_TYPE angletype, uint32_t radix, int32_t precision); extern void atananglerat(_Inout_ PRAT* px, AngleType angletype, uint32_t radix, int32_t precision);
// returns a new rat structure with the atanh of x->p/x->q // returns a new rat structure with the atanh of x->p/x->q
extern void atanhrat(_Inout_ PRAT* px, int32_t precision); extern void atanhrat(_Inout_ PRAT* px, int32_t precision);
@ -412,7 +407,7 @@ extern void cosrat(_Inout_ PRAT* px, uint32_t radix, int32_t precision);
// returns a new rat structure with the cos of x->p/x->q taking into account // returns a new rat structure with the cos of x->p/x->q taking into account
// angle type // angle type
extern void cosanglerat(_Inout_ PRAT* px, ANGLE_TYPE angletype, uint32_t radix, int32_t precision); extern void cosanglerat(_Inout_ PRAT* px, AngleType angletype, uint32_t radix, int32_t precision);
// returns a new rat structure with the exp of x->p/x->q this should not be called explicitly. // returns a new rat structure with the exp of x->p/x->q this should not be called explicitly.
extern void _exprat(_Inout_ PRAT* px, int32_t precision); extern void _exprat(_Inout_ PRAT* px, int32_t precision);
@ -435,14 +430,14 @@ extern void sinrat(_Inout_ PRAT* px);
// returns a new rat structure with the sin of x->p/x->q taking into account // returns a new rat structure with the sin of x->p/x->q taking into account
// angle type // angle type
extern void sinanglerat(_Inout_ PRAT* px, ANGLE_TYPE angletype, uint32_t radix, int32_t precision); extern void sinanglerat(_Inout_ PRAT* px, AngleType angletype, uint32_t radix, int32_t precision);
extern void tanhrat(_Inout_ PRAT* px, uint32_t radix, int32_t precision); extern void tanhrat(_Inout_ PRAT* px, uint32_t radix, int32_t precision);
extern void tanrat(_Inout_ PRAT* px, uint32_t radix, int32_t precision); extern void tanrat(_Inout_ PRAT* px, uint32_t radix, int32_t precision);
// returns a new rat structure with the tan of x->p/x->q taking into account // returns a new rat structure with the tan of x->p/x->q taking into account
// angle type // angle type
extern void tananglerat(_Inout_ PRAT* px, ANGLE_TYPE angletype, uint32_t radix, int32_t precision); extern void tananglerat(_Inout_ PRAT* px, AngleType angletype, uint32_t radix, int32_t precision);
extern void _dupnum(_In_ PNUMBER dest, _In_ const NUMBER* const src); extern void _dupnum(_In_ PNUMBER dest, _In_ const NUMBER* const src);

View File

@ -16,17 +16,17 @@
#include "ratpak.h" #include "ratpak.h"
void scalerat(_Inout_ PRAT* pa, ANGLE_TYPE angletype, uint32_t radix, int32_t precision) void scalerat(_Inout_ PRAT* pa, AngleType angletype, uint32_t radix, int32_t precision)
{ {
switch (angletype) switch (angletype)
{ {
case ANGLE_RAD: case AngleType::Radians:
scale2pi(pa, radix, precision); scale2pi(pa, radix, precision);
break; break;
case ANGLE_DEG: case AngleType::Degrees:
scale(pa, rat_360, radix, precision); scale(pa, rat_360, radix, precision);
break; break;
case ANGLE_GRAD: case AngleType::Gradians:
scale(pa, rat_400, radix, precision); scale(pa, rat_400, radix, precision);
break; break;
} }
@ -98,13 +98,13 @@ void sinrat(PRAT* px, uint32_t radix, int32_t precision)
_sinrat(px, precision); _sinrat(px, precision);
} }
void sinanglerat(_Inout_ PRAT* pa, ANGLE_TYPE angletype, uint32_t radix, int32_t precision) void sinanglerat(_Inout_ PRAT* pa, AngleType angletype, uint32_t radix, int32_t precision)
{ {
scalerat(pa, angletype, radix, precision); scalerat(pa, angletype, radix, precision);
switch (angletype) switch (angletype)
{ {
case ANGLE_DEG: case AngleType::Degrees:
if (rat_gt(*pa, rat_180, precision)) if (rat_gt(*pa, rat_180, precision))
{ {
subrat(pa, rat_360, precision); subrat(pa, rat_360, precision);
@ -112,7 +112,7 @@ void sinanglerat(_Inout_ PRAT* pa, ANGLE_TYPE angletype, uint32_t radix, int32_t
divrat(pa, rat_180, precision); divrat(pa, rat_180, precision);
mulrat(pa, pi, precision); mulrat(pa, pi, precision);
break; break;
case ANGLE_GRAD: case AngleType::Gradians:
if (rat_gt(*pa, rat_200, precision)) if (rat_gt(*pa, rat_200, precision))
{ {
subrat(pa, rat_400, precision); subrat(pa, rat_400, precision);
@ -193,13 +193,13 @@ void cosrat(_Inout_ PRAT* px, uint32_t radix, int32_t precision)
_cosrat(px, radix, precision); _cosrat(px, radix, precision);
} }
void cosanglerat(_Inout_ PRAT* pa, ANGLE_TYPE angletype, uint32_t radix, int32_t precision) void cosanglerat(_Inout_ PRAT* pa, AngleType angletype, uint32_t radix, int32_t precision)
{ {
scalerat(pa, angletype, radix, precision); scalerat(pa, angletype, radix, precision);
switch (angletype) switch (angletype)
{ {
case ANGLE_DEG: case AngleType::Degrees:
if (rat_gt(*pa, rat_180, precision)) if (rat_gt(*pa, rat_180, precision))
{ {
PRAT ptmp = nullptr; PRAT ptmp = nullptr;
@ -211,7 +211,7 @@ void cosanglerat(_Inout_ PRAT* pa, ANGLE_TYPE angletype, uint32_t radix, int32_t
divrat(pa, rat_180, precision); divrat(pa, rat_180, precision);
mulrat(pa, pi, precision); mulrat(pa, pi, precision);
break; break;
case ANGLE_GRAD: case AngleType::Gradians:
if (rat_gt(*pa, rat_200, precision)) if (rat_gt(*pa, rat_200, precision))
{ {
PRAT ptmp = nullptr; PRAT ptmp = nullptr;
@ -263,13 +263,13 @@ void tanrat(_Inout_ PRAT* px, uint32_t radix, int32_t precision)
_tanrat(px, radix, precision); _tanrat(px, radix, precision);
} }
void tananglerat(_Inout_ PRAT* pa, ANGLE_TYPE angletype, uint32_t radix, int32_t precision) void tananglerat(_Inout_ PRAT* pa, AngleType angletype, uint32_t radix, int32_t precision)
{ {
scalerat(pa, angletype, radix, precision); scalerat(pa, angletype, radix, precision);
switch (angletype) switch (angletype)
{ {
case ANGLE_DEG: case AngleType::Degrees:
if (rat_gt(*pa, rat_180, precision)) if (rat_gt(*pa, rat_180, precision))
{ {
subrat(pa, rat_180, precision); subrat(pa, rat_180, precision);
@ -277,7 +277,7 @@ void tananglerat(_Inout_ PRAT* pa, ANGLE_TYPE angletype, uint32_t radix, int32_t
divrat(pa, rat_180, precision); divrat(pa, rat_180, precision);
mulrat(pa, pi, precision); mulrat(pa, pi, precision);
break; break;
case ANGLE_GRAD: case AngleType::Gradians:
if (rat_gt(*pa, rat_200, precision)) if (rat_gt(*pa, rat_200, precision))
{ {
subrat(pa, rat_200, precision); subrat(pa, rat_200, precision);

View File

@ -41,11 +41,11 @@ void HistoryViewModel::ReloadHistory(_In_ ViewMode currentMode)
{ {
if (currentMode == ViewMode::Standard) if (currentMode == ViewMode::Standard)
{ {
m_currentMode = CalculationManager::CALCULATOR_MODE::CM_STD; m_currentMode = CalculationManager::CalculatorMode::Standard;
} }
else if (currentMode == ViewMode::Scientific) else if (currentMode == ViewMode::Scientific)
{ {
m_currentMode = CalculationManager::CALCULATOR_MODE::CM_SCI; m_currentMode = CalculationManager::CalculatorMode::Scientific;
} }
else else
{ {
@ -127,7 +127,7 @@ void HistoryViewModel::DeleteItem(_In_ HistoryItemViewModel ^ e)
{ {
// Keys for the history container are index based. // Keys for the history container are index based.
// SaveHistory() re-inserts the items anyway, so it's faster to just clear out the container. // SaveHistory() re-inserts the items anyway, so it's faster to just clear out the container.
CalculationManager::CALCULATOR_MODE currentMode = m_currentMode; CalculationManager::CalculatorMode currentMode = m_currentMode;
ApplicationDataContainer ^ historyContainer = GetHistoryContainer(currentMode); ApplicationDataContainer ^ historyContainer = GetHistoryContainer(currentMode);
historyContainer->Values->Clear(); historyContainer->Values->Clear();
@ -152,7 +152,7 @@ void HistoryViewModel::OnClearCommand(_In_ Platform::Object ^ e)
if (Items->Size > 0) if (Items->Size > 0)
{ {
CalculationManager::CALCULATOR_MODE currentMode = m_currentMode; CalculationManager::CalculatorMode currentMode = m_currentMode;
ClearHistoryContainer(currentMode); ClearHistoryContainer(currentMode);
Items->Clear(); Items->Clear();
UpdateItemSize(); UpdateItemSize();
@ -167,7 +167,7 @@ void HistoryViewModel::OnClearCommand(_In_ Platform::Object ^ e)
} }
// this method restores history vector per mode // this method restores history vector per mode
void HistoryViewModel::RestoreHistory(_In_ CalculationManager::CALCULATOR_MODE cMode) void HistoryViewModel::RestoreHistory(_In_ CalculationManager::CalculatorMode cMode)
{ {
ApplicationDataContainer ^ historyContainer = GetHistoryContainer(cMode); ApplicationDataContainer ^ historyContainer = GetHistoryContainer(cMode);
std::shared_ptr<std::vector<std::shared_ptr<CalculationManager::HISTORYITEM>>> historyVector = std::shared_ptr<std::vector<std::shared_ptr<CalculationManager::HISTORYITEM>>> historyVector =
@ -209,13 +209,13 @@ void HistoryViewModel::RestoreHistory(_In_ CalculationManager::CALCULATOR_MODE c
} }
} }
Platform::String ^ HistoryViewModel::GetHistoryContainerKey(_In_ CalculationManager::CALCULATOR_MODE cMode) Platform::String ^ HistoryViewModel::GetHistoryContainerKey(_In_ CalculationManager::CalculatorMode cMode)
{ {
Platform::ValueType ^ modeValue = static_cast<int>(cMode); Platform::ValueType ^ modeValue = static_cast<int>(cMode);
return Platform::String::Concat(modeValue->ToString(), L"_History"); return Platform::String::Concat(modeValue->ToString(), L"_History");
} }
ApplicationDataContainer ^ HistoryViewModel::GetHistoryContainer(_In_ CalculationManager::CALCULATOR_MODE cMode) ApplicationDataContainer ^ HistoryViewModel::GetHistoryContainer(_In_ CalculationManager::CalculatorMode cMode)
{ {
ApplicationDataContainer ^ localSettings = ApplicationData::Current->LocalSettings; ApplicationDataContainer ^ localSettings = ApplicationData::Current->LocalSettings;
ApplicationDataContainer ^ historyContainer; ApplicationDataContainer ^ historyContainer;
@ -238,14 +238,14 @@ ApplicationDataContainer ^ HistoryViewModel::GetHistoryContainer(_In_ Calculatio
return historyContainer; return historyContainer;
} }
void HistoryViewModel::ClearHistoryContainer(_In_ CalculationManager::CALCULATOR_MODE cMode) void HistoryViewModel::ClearHistoryContainer(_In_ CalculationManager::CalculatorMode cMode)
{ {
ApplicationDataContainer ^ localSettings = ApplicationData::Current->LocalSettings; ApplicationDataContainer ^ localSettings = ApplicationData::Current->LocalSettings;
localSettings->DeleteContainer(GetHistoryContainerKey(cMode)); localSettings->DeleteContainer(GetHistoryContainerKey(cMode));
} }
// this method will be used to update the history item length // this method will be used to update the history item length
void HistoryViewModel::UpdateHistoryVectorLength(_In_ int newValue, _In_ CalculationManager::CALCULATOR_MODE cMode) void HistoryViewModel::UpdateHistoryVectorLength(_In_ int newValue, _In_ CalculationManager::CalculatorMode cMode)
{ {
ApplicationDataContainer ^ historyContainer = GetHistoryContainer(cMode); ApplicationDataContainer ^ historyContainer = GetHistoryContainer(cMode);
historyContainer->Values->Remove(HistoryVectorLengthKey); historyContainer->Values->Remove(HistoryVectorLengthKey);
@ -254,8 +254,8 @@ void HistoryViewModel::UpdateHistoryVectorLength(_In_ int newValue, _In_ Calcula
void HistoryViewModel::ClearHistory() void HistoryViewModel::ClearHistory()
{ {
ClearHistoryContainer(CalculationManager::CALCULATOR_MODE::CM_STD); ClearHistoryContainer(CalculationManager::CalculatorMode::Standard);
ClearHistoryContainer(CalculationManager::CALCULATOR_MODE::CM_SCI); ClearHistoryContainer(CalculationManager::CalculatorMode::Scientific);
} }
void HistoryViewModel::SaveHistory() void HistoryViewModel::SaveHistory()

View File

@ -55,16 +55,16 @@ namespace CalculatorApp
private: private:
CalculationManager::CalculatorManager* const m_calculatorManager; CalculationManager::CalculatorManager* const m_calculatorManager;
CalculatorDisplay m_calculatorDisplay; CalculatorDisplay m_calculatorDisplay;
CalculationManager::CALCULATOR_MODE m_currentMode; CalculationManager::CalculatorMode m_currentMode;
Platform::String ^ m_localizedHistoryCleared; Platform::String ^ m_localizedHistoryCleared;
void RestoreHistory(_In_ CalculationManager::CALCULATOR_MODE cMode); void RestoreHistory(_In_ CalculationManager::CalculatorMode cMode);
CalculationManager::HISTORYITEM CalculationManager::HISTORYITEM
DeserializeHistoryItem(_In_ Platform::String ^ historyItemKey, _In_ Windows::Storage::ApplicationDataContainer ^ historyContainer); DeserializeHistoryItem(_In_ Platform::String ^ historyItemKey, _In_ Windows::Storage::ApplicationDataContainer ^ historyContainer);
Windows::Storage::ApplicationDataContainer ^ GetHistoryContainer(_In_ CalculationManager::CALCULATOR_MODE cMode); Windows::Storage::ApplicationDataContainer ^ GetHistoryContainer(_In_ CalculationManager::CalculatorMode cMode);
Platform::String ^ GetHistoryContainerKey(_In_ CalculationManager::CALCULATOR_MODE cMode); Platform::String ^ GetHistoryContainerKey(_In_ CalculationManager::CalculatorMode cMode);
void ClearHistoryContainer(_In_ CalculationManager::CALCULATOR_MODE cMode); void ClearHistoryContainer(_In_ CalculationManager::CalculatorMode cMode);
void UpdateHistoryVectorLength(_In_ int newValue, _In_ CalculationManager::CALCULATOR_MODE cMode); void UpdateHistoryVectorLength(_In_ int newValue, _In_ CalculationManager::CalculatorMode cMode);
bool IsValid(_In_ CalculationManager::HISTORYITEM item); bool IsValid(_In_ CalculationManager::HISTORYITEM item);
friend class CalculatorDisplay; friend class CalculatorDisplay;

View File

@ -679,18 +679,18 @@ void StandardCalculatorViewModel::OnButtonPressed(Object ^ parameter)
} }
} }
RADIX_TYPE StandardCalculatorViewModel::GetRadixTypeFromNumberBase(NumberBase base) RadixType StandardCalculatorViewModel::GetRadixTypeFromNumberBase(NumberBase base)
{ {
switch (base) switch (base)
{ {
case NumberBase::BinBase: case NumberBase::BinBase:
return RADIX_TYPE::BIN_RADIX; return RadixType::Binary;
case NumberBase::HexBase: case NumberBase::HexBase:
return RADIX_TYPE::HEX_RADIX; return RadixType::Hex;
case NumberBase::OctBase: case NumberBase::OctBase:
return RADIX_TYPE::OCT_RADIX; return RadixType::Octal;
default: default:
return RADIX_TYPE::DEC_RADIX; return RadixType::Decimal;
} }
} }
@ -1228,7 +1228,7 @@ void StandardCalculatorViewModel::ResetDisplay()
{ {
AreHEXButtonsEnabled = false; AreHEXButtonsEnabled = false;
CurrentRadixType = NumberBase::DecBase; CurrentRadixType = NumberBase::DecBase;
m_standardCalculatorManager.SetRadix(DEC_RADIX); m_standardCalculatorManager.SetRadix(RadixType::Decimal);
} }
void StandardCalculatorViewModel::SetPrecision(int32_t precision) void StandardCalculatorViewModel::SetPrecision(int32_t precision)
@ -1253,16 +1253,16 @@ void StandardCalculatorViewModel::SetMemorizedNumbersString()
m_standardCalculatorManager.SetMemorizedNumbersString(); m_standardCalculatorManager.SetMemorizedNumbersString();
} }
ANGLE_TYPE GetAngleTypeFromCommand(Command command) AngleType GetAngleTypeFromCommand(Command command)
{ {
switch (command) switch (command)
{ {
case Command::CommandDEG: case Command::CommandDEG:
return ANGLE_DEG; return AngleType::Degrees;
case Command::CommandRAD: case Command::CommandRAD:
return ANGLE_RAD; return AngleType::Radians;
case Command::CommandGRAD: case Command::CommandGRAD:
return ANGLE_GRAD; return AngleType::Gradians;
default: default:
throw ref new Exception(E_FAIL, L"Invalid command type"); throw ref new Exception(E_FAIL, L"Invalid command type");
} }
@ -1279,7 +1279,7 @@ void StandardCalculatorViewModel::SaveEditedCommand(_In_ unsigned int tokenPosit
if (IsUnaryOp(command) && command != Command::CommandSIGN) if (IsUnaryOp(command) && command != Command::CommandSIGN)
{ {
int angleCmd = static_cast<int>(m_standardCalculatorManager.GetCurrentDegreeMode()); int angleCmd = static_cast<int>(m_standardCalculatorManager.GetCurrentDegreeMode());
ANGLE_TYPE angleType = GetAngleTypeFromCommand(static_cast<Command>(angleCmd)); AngleType angleType = GetAngleTypeFromCommand(static_cast<Command>(angleCmd));
if (IsTrigOp(command)) if (IsTrigOp(command))
{ {

View File

@ -307,7 +307,7 @@ namespace CalculatorApp
_Inout_ std::shared_ptr<std::vector<std::shared_ptr<IExpressionCommand>>> const& commands); _Inout_ std::shared_ptr<std::vector<std::shared_ptr<IExpressionCommand>>> const& commands);
void SetTokens(_Inout_ std::shared_ptr<std::vector<std::pair<std::wstring, int>>> const& tokens); void SetTokens(_Inout_ std::shared_ptr<std::vector<std::pair<std::wstring, int>>> const& tokens);
NumbersAndOperatorsEnum ConvertIntegerToNumbersAndOperatorsEnum(unsigned int parameter); NumbersAndOperatorsEnum ConvertIntegerToNumbersAndOperatorsEnum(unsigned int parameter);
static RADIX_TYPE GetRadixTypeFromNumberBase(CalculatorApp::Common::NumberBase base); static RadixType GetRadixTypeFromNumberBase(CalculatorApp::Common::NumberBase base);
NumbersAndOperatorsEnum m_CurrentAngleType; NumbersAndOperatorsEnum m_CurrentAngleType;
wchar_t m_decimalSeparator; wchar_t m_decimalSeparator;
CalculatorDisplay m_calculatorDisplay; CalculatorDisplay m_calculatorDisplay;

View File

@ -26,22 +26,22 @@ namespace CalculatorApp
auto resourceLoader = AppResourceProvider::GetInstance(); auto resourceLoader = AppResourceProvider::GetInstance();
switch (boxedInt->Value) switch (boxedInt->Value)
{ {
case RADIX_TYPE::BIN_RADIX: case RadixType::Binary:
{ {
convertedValue = resourceLoader->GetResourceString("Bin"); convertedValue = resourceLoader->GetResourceString("Bin");
break; break;
} }
case RADIX_TYPE::OCT_RADIX: case RadixType::Octal:
{ {
convertedValue = resourceLoader->GetResourceString("Oct"); convertedValue = resourceLoader->GetResourceString("Oct");
break; break;
} }
case RADIX_TYPE::DEC_RADIX: case RadixType::Decimal:
{ {
convertedValue = resourceLoader->GetResourceString("Dec"); convertedValue = resourceLoader->GetResourceString("Dec");
break; break;
} }
case RADIX_TYPE::HEX_RADIX: case RadixType::Hex:
{ {
convertedValue = resourceLoader->GetResourceString("Hex"); convertedValue = resourceLoader->GetResourceString("Hex");
break; break;

View File

@ -65,7 +65,7 @@ namespace CalculatorFunctionalTests
return !(localSettings->Containers->HasKey(historyContainerKey)); return !(localSettings->Containers->HasKey(historyContainerKey));
} }
String^ GetHistoryContainerKeyHelper(CalculationManager::CALCULATOR_MODE cMode) String^ GetHistoryContainerKeyHelper(CalculationManager::CalculatorMode cMode)
{ {
ValueType^ modeValue = static_cast<int>(cMode); ValueType^ modeValue = static_cast<int>(cMode);
return String::Concat(modeValue->ToString(), L"_History"); return String::Concat(modeValue->ToString(), L"_History");
@ -204,8 +204,8 @@ namespace CalculatorFunctionalTests
m_standardViewModel->m_standardCalculatorManager.SendCommand(Command::CommandEQU); m_standardViewModel->m_standardCalculatorManager.SendCommand(Command::CommandEQU);
m_historyViewModel->OnClearCommand(nullptr); m_historyViewModel->OnClearCommand(nullptr);
VERIFY_ARE_EQUAL(0, m_historyViewModel->ItemSize); VERIFY_ARE_EQUAL(0, m_historyViewModel->ItemSize);
VERIFY_IS_TRUE(IsHistoryContainerEmpty(GetHistoryContainerKeyHelper(CM_STD))); VERIFY_IS_TRUE(IsHistoryContainerEmpty(GetHistoryContainerKeyHelper(CalculatorMode::Standard)));
VERIFY_IS_TRUE(IsHistoryContainerEmpty(GetHistoryContainerKeyHelper(CM_SCI))); VERIFY_IS_TRUE(IsHistoryContainerEmpty(GetHistoryContainerKeyHelper(CalculatorMode::Scientific)));
Cleanup(); Cleanup();
} }

View File

@ -78,25 +78,25 @@ TEST_METHOD(TestModuloRational)
{ {
// Test with rational numbers // Test with rational numbers
auto res = Mod(Rational(Number(1, 0, { 250 }), Number(1, 0, { 100 })), Rational(89)); auto res = Mod(Rational(Number(1, 0, { 250 }), Number(1, 0, { 100 })), Rational(89));
VERIFY_ARE_EQUAL(res.ToString(10, FMT_FLOAT, 8), L"2.5"); VERIFY_ARE_EQUAL(res.ToString(10, NumberFormat::Float, 8), L"2.5");
res = Mod(Rational(Number(1, 0, { 3330 }), Number(1, 0, { 1332 })), Rational(1)); res = Mod(Rational(Number(1, 0, { 3330 }), Number(1, 0, { 1332 })), Rational(1));
VERIFY_ARE_EQUAL(res.ToString(10, FMT_FLOAT, 8), L"0.5"); VERIFY_ARE_EQUAL(res.ToString(10, NumberFormat::Float, 8), L"0.5");
res = Mod(Rational(Number(1, 0, { 12250 }), Number(1, 0, { 100 })), Rational(10)); res = Mod(Rational(Number(1, 0, { 12250 }), Number(1, 0, { 100 })), Rational(10));
VERIFY_ARE_EQUAL(res.ToString(10, FMT_FLOAT, 8), L"2.5"); VERIFY_ARE_EQUAL(res.ToString(10, NumberFormat::Float, 8), L"2.5");
res = Mod(Rational(Number(-1, 0, { 12250 }), Number(1, 0, { 100 })), Rational(10)); res = Mod(Rational(Number(-1, 0, { 12250 }), Number(1, 0, { 100 })), Rational(10));
VERIFY_ARE_EQUAL(res.ToString(10, FMT_FLOAT, 8), L"7.5"); VERIFY_ARE_EQUAL(res.ToString(10, NumberFormat::Float, 8), L"7.5");
res = Mod(Rational(Number(-1, 0, { 12250 }), Number(1, 0, { 100 })), Rational(-10)); res = Mod(Rational(Number(-1, 0, { 12250 }), Number(1, 0, { 100 })), Rational(-10));
VERIFY_ARE_EQUAL(res.ToString(10, FMT_FLOAT, 8), L"-2.5"); VERIFY_ARE_EQUAL(res.ToString(10, NumberFormat::Float, 8), L"-2.5");
res = Mod(Rational(Number(1, 0, { 12250 }), Number(1, 0, { 100 })), Rational(-10)); res = Mod(Rational(Number(1, 0, { 12250 }), Number(1, 0, { 100 })), Rational(-10));
VERIFY_ARE_EQUAL(res.ToString(10, FMT_FLOAT, 8), L"-7.5"); VERIFY_ARE_EQUAL(res.ToString(10, NumberFormat::Float, 8), L"-7.5");
res = Mod(Rational(Number(1, 0, { 1000 }), Number(1, 0, { 3 })), Rational(1)); res = Mod(Rational(Number(1, 0, { 1000 }), Number(1, 0, { 3 })), Rational(1));
VERIFY_ARE_EQUAL(res.ToString(10, FMT_FLOAT, 8), L"0.33333333"); VERIFY_ARE_EQUAL(res.ToString(10, NumberFormat::Float, 8), L"0.33333333");
res = Mod(Rational(Number(1, 0, { 1000 }), Number(1, 0, { 3 })), Rational(-10)); res = Mod(Rational(Number(1, 0, { 1000 }), Number(1, 0, { 3 })), Rational(-10));
VERIFY_ARE_EQUAL(res.ToString(10, FMT_FLOAT, 8), L"-6.6666667"); VERIFY_ARE_EQUAL(res.ToString(10, NumberFormat::Float, 8), L"-6.6666667");
res = Mod(Rational(834345), Rational(Number(1, 0, { 103 }), Number(1, 0, { 100 }))); res = Mod(Rational(834345), Rational(Number(1, 0, { 103 }), Number(1, 0, { 100 })));
VERIFY_ARE_EQUAL(res.ToString(10, FMT_FLOAT, 8), L"0.71"); VERIFY_ARE_EQUAL(res.ToString(10, NumberFormat::Float, 8), L"0.71");
res = Mod(Rational(834345), Rational(Number(-1, 0, { 103 }), Number(1, 0, { 100 }))); res = Mod(Rational(834345), Rational(Number(-1, 0, { 103 }), Number(1, 0, { 100 })));
VERIFY_ARE_EQUAL(res.ToString(10, FMT_FLOAT, 8), L"-0.32"); VERIFY_ARE_EQUAL(res.ToString(10, NumberFormat::Float, 8), L"-0.32");
} }
TEST_METHOD(TestRemainderOperandsNotModified) TEST_METHOD(TestRemainderOperandsNotModified)
@ -192,29 +192,29 @@ TEST_METHOD(TestRemainderRational)
{ {
// Test with rational numbers // Test with rational numbers
auto res = Rational(Number(1, 0, { 250 }), Number(1, 0, { 100 })) % Rational(89); auto res = Rational(Number(1, 0, { 250 }), Number(1, 0, { 100 })) % Rational(89);
VERIFY_ARE_EQUAL(res.ToString(10, FMT_FLOAT, 8), L"2.5"); VERIFY_ARE_EQUAL(res.ToString(10, NumberFormat::Float, 8), L"2.5");
res = Rational(Number(1, 0, { 3330 }), Number(1, 0, { 1332 })) % Rational(1); res = Rational(Number(1, 0, { 3330 }), Number(1, 0, { 1332 })) % Rational(1);
VERIFY_ARE_EQUAL(res.ToString(10, FMT_FLOAT, 8), L"0.5"); VERIFY_ARE_EQUAL(res.ToString(10, NumberFormat::Float, 8), L"0.5");
res = Rational(Number(1, 0, { 12250 }), Number(1, 0, { 100 })) % Rational(10); res = Rational(Number(1, 0, { 12250 }), Number(1, 0, { 100 })) % Rational(10);
VERIFY_ARE_EQUAL(res.ToString(10, FMT_FLOAT, 8), L"2.5"); VERIFY_ARE_EQUAL(res.ToString(10, NumberFormat::Float, 8), L"2.5");
res = Rational(Number(-1, 0, { 12250 }), Number(1, 0, { 100 })) % Rational(10); res = Rational(Number(-1, 0, { 12250 }), Number(1, 0, { 100 })) % Rational(10);
VERIFY_ARE_EQUAL(res.ToString(10, FMT_FLOAT, 8), L"-2.5"); VERIFY_ARE_EQUAL(res.ToString(10, NumberFormat::Float, 8), L"-2.5");
res = Rational(Number(-1, 0, { 12250 }), Number(1, 0, { 100 })) % Rational(-10); res = Rational(Number(-1, 0, { 12250 }), Number(1, 0, { 100 })) % Rational(-10);
VERIFY_ARE_EQUAL(res.ToString(10, FMT_FLOAT, 8), L"-2.5"); VERIFY_ARE_EQUAL(res.ToString(10, NumberFormat::Float, 8), L"-2.5");
res = Rational(Number(1, 0, { 12250 }), Number(1, 0, { 100 })) % Rational(-10); res = Rational(Number(1, 0, { 12250 }), Number(1, 0, { 100 })) % Rational(-10);
VERIFY_ARE_EQUAL(res.ToString(10, FMT_FLOAT, 8), L"2.5"); VERIFY_ARE_EQUAL(res.ToString(10, NumberFormat::Float, 8), L"2.5");
res = Rational(Number(1, 0, { 1000 }), Number(1, 0, { 3 })) % Rational(1); res = Rational(Number(1, 0, { 1000 }), Number(1, 0, { 3 })) % Rational(1);
VERIFY_ARE_EQUAL(res.ToString(10, FMT_FLOAT, 8), L"0.33333333"); VERIFY_ARE_EQUAL(res.ToString(10, NumberFormat::Float, 8), L"0.33333333");
res = Rational(Number(1, 0, { 1000 }), Number(1, 0, { 3 })) % Rational(-10); res = Rational(Number(1, 0, { 1000 }), Number(1, 0, { 3 })) % Rational(-10);
VERIFY_ARE_EQUAL(res.ToString(10, FMT_FLOAT, 8), L"3.3333333"); VERIFY_ARE_EQUAL(res.ToString(10, NumberFormat::Float, 8), L"3.3333333");
res = Rational(Number(-1, 0, { 1000 }), Number(1, 0, { 3 })) % Rational(-10); res = Rational(Number(-1, 0, { 1000 }), Number(1, 0, { 3 })) % Rational(-10);
VERIFY_ARE_EQUAL(res.ToString(10, FMT_FLOAT, 8), L"-3.3333333"); VERIFY_ARE_EQUAL(res.ToString(10, NumberFormat::Float, 8), L"-3.3333333");
res = Rational(834345) % Rational(Number(1, 0, { 103 }), Number(1, 0, { 100 })); res = Rational(834345) % Rational(Number(1, 0, { 103 }), Number(1, 0, { 100 }));
VERIFY_ARE_EQUAL(res.ToString(10, FMT_FLOAT, 8), L"0.71"); VERIFY_ARE_EQUAL(res.ToString(10, NumberFormat::Float, 8), L"0.71");
res = Rational(834345) % Rational(Number(-1, 0, { 103 }), Number(1, 0, { 100 })); res = Rational(834345) % Rational(Number(-1, 0, { 103 }), Number(1, 0, { 100 }));
VERIFY_ARE_EQUAL(res.ToString(10, FMT_FLOAT, 8), L"0.71"); VERIFY_ARE_EQUAL(res.ToString(10, NumberFormat::Float, 8), L"0.71");
res = Rational(-834345) % Rational(Number(1, 0, { 103 }), Number(1, 0, { 100 })); res = Rational(-834345) % Rational(Number(1, 0, { 103 }), Number(1, 0, { 100 }));
VERIFY_ARE_EQUAL(res.ToString(10, FMT_FLOAT, 8), L"-0.71"); VERIFY_ARE_EQUAL(res.ToString(10, NumberFormat::Float, 8), L"-0.71");
} }
} }
; ;

View File

@ -510,19 +510,19 @@ namespace CalculatorUnitTests
TEST_METHOD(ProgrammerModeButtonsDisable) TEST_METHOD(ProgrammerModeButtonsDisable)
{ {
/* m_viewModel->IsProgrammer = true; /* m_viewModel->IsProgrammer = true;
m_viewModel->SwitchProgrammerModeBase(OCT_RADIX); m_viewModel->SwitchProgrammerModeBase(RadixType::Octal);
VERIFY_IS_TRUE(m_viewModel->AreOCTButtonsEnabled); VERIFY_IS_TRUE(m_viewModel->AreOCTButtonsEnabled);
VERIFY_IS_FALSE(m_viewModel->AreHEXButtonsEnabled); VERIFY_IS_FALSE(m_viewModel->AreHEXButtonsEnabled);
VERIFY_IS_FALSE(m_viewModel->AreDECButtonsEnabled); VERIFY_IS_FALSE(m_viewModel->AreDECButtonsEnabled);
m_viewModel->SwitchProgrammerModeBase(DEC_RADIX); m_viewModel->SwitchProgrammerModeBase(RadixType::Decimal);
VERIFY_IS_FALSE(m_viewModel->AreHEXButtonsEnabled); VERIFY_IS_FALSE(m_viewModel->AreHEXButtonsEnabled);
VERIFY_IS_TRUE(m_viewModel->AreDECButtonsEnabled); VERIFY_IS_TRUE(m_viewModel->AreDECButtonsEnabled);
VERIFY_IS_TRUE(m_viewModel->AreOCTButtonsEnabled); VERIFY_IS_TRUE(m_viewModel->AreOCTButtonsEnabled);
m_viewModel->SwitchProgrammerModeBase(HEX_RADIX); m_viewModel->SwitchProgrammerModeBase(RadixType::Hex);
VERIFY_IS_TRUE(m_viewModel->AreHEXButtonsEnabled); VERIFY_IS_TRUE(m_viewModel->AreHEXButtonsEnabled);
VERIFY_IS_TRUE(m_viewModel->AreDECButtonsEnabled); VERIFY_IS_TRUE(m_viewModel->AreDECButtonsEnabled);
VERIFY_IS_TRUE(m_viewModel->AreOCTButtonsEnabled); VERIFY_IS_TRUE(m_viewModel->AreOCTButtonsEnabled);
m_viewModel->SwitchProgrammerModeBase(BIN_RADIX); m_viewModel->SwitchProgrammerModeBase(RadixType::Binary);
VERIFY_IS_FALSE(m_viewModel->AreHEXButtonsEnabled); VERIFY_IS_FALSE(m_viewModel->AreHEXButtonsEnabled);
VERIFY_IS_FALSE(m_viewModel->AreDECButtonsEnabled); VERIFY_IS_FALSE(m_viewModel->AreDECButtonsEnabled);
VERIFY_IS_FALSE(m_viewModel->AreOCTButtonsEnabled);*/ VERIFY_IS_FALSE(m_viewModel->AreOCTButtonsEnabled);*/