diff --git a/src/CalcManager/CEngine/History.cpp b/src/CalcManager/CEngine/History.cpp index e002e62a..52038675 100644 --- a/src/CalcManager/CEngine/History.cpp +++ b/src/CalcManager/CEngine/History.cpp @@ -194,7 +194,7 @@ void CHistoryCollector::AddCloseBraceToHistory() void CHistoryCollector::EnclosePrecInversionBrackets() { - // Top of the Opnd starts index or 0 is nothing is in top + // Top of the Opnd starts index or 0 if nothing is in top int ichStart = (m_curOperandIndex > 0) ? m_operandIndices[m_curOperandIndex - 1] : 0; InsertSzInEquationSz(CCalcEngine::OpCodeToString(IDC_OPENP), -1, ichStart); @@ -203,7 +203,7 @@ void CHistoryCollector::EnclosePrecInversionBrackets() bool CHistoryCollector::FOpndAddedToHistory() { - return (-1 != m_lastOpStartIndex); + return (m_lastOpStartIndex != -1); } // AddUnaryOpToHistory diff --git a/src/CalcManager/CEngine/scicomm.cpp b/src/CalcManager/CEngine/scicomm.cpp index d7655b27..490e461e 100644 --- a/src/CalcManager/CEngine/scicomm.cpp +++ b/src/CalcManager/CEngine/scicomm.cpp @@ -610,7 +610,7 @@ void CCalcEngine::ProcessCommandWorker(OpCode wParam) } // Set the "(=xx" indicator. - if (nullptr != m_pCalcDisplay) + if (m_pCalcDisplay != nullptr) { m_pCalcDisplay->SetParenthesisNumber(m_openParenCount >= 0 ? static_cast(m_openParenCount) : 0); } diff --git a/src/CalcManager/Ratpack/conv.cpp b/src/CalcManager/Ratpack/conv.cpp index 4f7609de..a618ef64 100644 --- a/src/CalcManager/Ratpack/conv.cpp +++ b/src/CalcManager/Ratpack/conv.cpp @@ -358,10 +358,9 @@ PNUMBER numtonRadixx(_In_ PNUMBER a, uint32_t radix) { PNUMBER pnumret = i32tonum(0, BASEX); // pnumret is the number in internal form. PNUMBER num_radix = i32tonum(radix, BASEX); - MANTTYPE* ptrdigit = a->mant; // pointer to digit being worked on. // Digits are in reverse order, back over them LSD first. - ptrdigit += a->cdigit - 1; + MANTTYPE* ptrdigit = a->mant + a->cdigit - 1; // pointer to digit being worked on. PNUMBER thisdigit = nullptr; // thisdigit holds the current digit of a for (int32_t idigit = 0; idigit < a->cdigit; idigit++) @@ -992,8 +991,7 @@ int32_t numtoi32(_In_ PNUMBER pnum, uint32_t radix) { int32_t lret = 0; - MANTTYPE* pmant = pnum->mant; - pmant += pnum->cdigit - 1; + MANTTYPE* pmant = pnum->mant + pnum->cdigit - 1; int32_t expt = pnum->exp; for (int32_t length = pnum->cdigit; length > 0 && length + expt > 0; length--) @@ -1002,9 +1000,10 @@ int32_t numtoi32(_In_ PNUMBER pnum, uint32_t radix) lret += *(pmant--); } - while (expt-- > 0) + while (expt > 0) { lret *= radix; + expt--; } lret *= pnum->sign; @@ -1050,7 +1049,7 @@ bool stripzeroesnum(_Inout_ PNUMBER pnum, int32_t starting) if (fstrip) { // Remove them. - memmove(pnum->mant, pmant, (int)(cdigits * sizeof(MANTTYPE))); + memmove(pnum->mant, pmant, static_cast(cdigits * sizeof(MANTTYPE))); // And adjust exponent and digit count accordingly. pnum->exp += (pnum->cdigit - cdigits); pnum->cdigit = cdigits; @@ -1404,11 +1403,9 @@ PNUMBER gcd(_In_ PNUMBER a, _In_ PNUMBER b) PNUMBER i32factnum(int32_t ini32, uint32_t radix) { - PNUMBER lret = nullptr; + PNUMBER lret = i32tonum(1, radix); PNUMBER tmp = nullptr; - lret = i32tonum(1, radix); - while (ini32 > 0) { tmp = i32tonum(ini32--, radix); @@ -1434,11 +1431,9 @@ PNUMBER i32factnum(int32_t ini32, uint32_t radix) PNUMBER i32prodnum(int32_t start, int32_t stop, uint32_t radix) { - PNUMBER lret = nullptr; + PNUMBER lret = i32tonum(1, radix); PNUMBER tmp = nullptr; - lret = i32tonum(1, radix); - while (start <= stop) { if (start) diff --git a/src/CalcManager/Ratpack/num.cpp b/src/CalcManager/Ratpack/num.cpp index 6055e41d..e2be447a 100644 --- a/src/CalcManager/Ratpack/num.cpp +++ b/src/CalcManager/Ratpack/num.cpp @@ -408,7 +408,7 @@ void _divnum(PNUMBER* pa, PNUMBER b, uint32_t radix, int32_t precision) // Build a table of multiplications of the divisor, this is quicker for // more than radix 'digits' list numberList{ i32tonum(0L, radix) }; - for (uint32_t i = 1; i < radix; i++) + for (uint32_t i = radix; i > 1; i--) { PNUMBER newValue = nullptr; DUPNUM(newValue, numberList.front()); @@ -418,12 +418,11 @@ void _divnum(PNUMBER* pa, PNUMBER b, uint32_t radix, int32_t precision) } destroynum(tmp); - int32_t digit; int32_t cdigits = 0; while (cdigits++ < thismax && !zernum(rem)) { - digit = radix - 1; - PNUMBER multiple = nullptr; + uint32_t digit = radix - 1; + PNUMBER multiple = rem; for (const auto& num : numberList) { if (!lessnum(rem, num) || !--digit) @@ -446,7 +445,7 @@ void _divnum(PNUMBER* pa, PNUMBER b, uint32_t radix, int32_t precision) if (c->mant != ++ptrc) { - memmove(c->mant, ptrc, (int)(cdigits * sizeof(MANTTYPE))); + memmove(c->mant, ptrc, static_cast(cdigits * sizeof(MANTTYPE))); } // Cleanup table structure @@ -515,12 +514,9 @@ bool equnum(_In_ PNUMBER a, _In_ PNUMBER b) else { // OK the exponents match. - pa = a->mant; - pb = b->mant; - pa += a->cdigit - 1; - pb += b->cdigit - 1; - cdigits = max(a->cdigit, b->cdigit); - ccdigits = cdigits; + pa = a->mant + a->cdigit - 1; + pb = b->mant + b->cdigit - 1; + ccdigits = cdigits = max(a->cdigit, b->cdigit); // Loop over all digits until we run out of digits or there is a // difference in the digits. @@ -602,14 +598,11 @@ bool lessnum(_In_ PNUMBER a, _In_ PNUMBER b) bool zernum(_In_ PNUMBER a) { - int32_t length; - MANTTYPE* pcha; - length = a->cdigit; - pcha = a->mant; + MANTTYPE* pcha = a->mant; // loop over all the digits until you find a nonzero or until you run // out of digits - while (length-- > 0) + for (auto length = a->cdigit; length > 0; length--) { if (*pcha++) {