From 5e4eaf636a8c958316c3a5e1df8f6c3bc4329eb1 Mon Sep 17 00:00:00 2001 From: Josh Koon <45607479+joshkoon@users.noreply.github.com> Date: Thu, 21 Feb 2019 12:09:13 -0800 Subject: [PATCH] Remove unnecessary precision arguments from Rational class and remove use of explicit Rational constructors in favor of implicit conversions for value types --- src/CalcManager/CEngine/Rational.cpp | 8 ++++---- src/CalcManager/CEngine/scicomm.cpp | 14 +++++++------- src/CalcManager/CEngine/scidisp.cpp | 2 +- src/CalcManager/CEngine/scifunc.cpp | 12 ++++++------ src/CalcManager/CEngine/scioper.cpp | 12 ++++++------ src/CalcManager/CEngine/sciset.cpp | 4 ++-- src/CalcManager/Header Files/Rational.h | 6 +++--- 7 files changed, 29 insertions(+), 29 deletions(-) diff --git a/src/CalcManager/CEngine/Rational.cpp b/src/CalcManager/CEngine/Rational.cpp index c6a3432d..b7d43c9a 100644 --- a/src/CalcManager/CEngine/Rational.cpp +++ b/src/CalcManager/CEngine/Rational.cpp @@ -50,7 +50,7 @@ namespace CalcEngine destroyrat(pr); } - Rational::Rational(uint64_t ui, int32_t precision) + Rational::Rational(uint64_t ui) { uint32_t hi = HIDWORD(ui); uint32_t lo = LODWORD(ui); @@ -379,7 +379,7 @@ namespace CalcEngine return lhs; } - Rational Rational::Not(Rational const& chopNum, int32_t precision) const + Rational Rational::Not(Rational const& chopNum) const { return *this ^ chopNum; } @@ -475,13 +475,13 @@ namespace CalcEngine return result; } - uint64_t Rational::ToUInt64_t(int32_t precision) const + uint64_t Rational::ToUInt64_t() const { PRAT rat = this->ToPRAT(); uint64_t result; try { - result = rattoUlonglong(rat, RATIONAL_BASE, precision); + result = rattoUlonglong(rat, RATIONAL_BASE, RATIONAL_PRECISION); } catch (DWORD error) { diff --git a/src/CalcManager/CEngine/scicomm.cpp b/src/CalcManager/CEngine/scicomm.cpp index 9f8284b0..25cf1c70 100644 --- a/src/CalcManager/CEngine/scicomm.cpp +++ b/src/CalcManager/CEngine/scicomm.cpp @@ -382,7 +382,7 @@ void CCalcEngine::ProcessCommandWorker(WPARAM wParam) CheckAndAddLastBinOpToHistory(false); } - m_lastVal = Rational{}; + m_lastVal = 0; m_bChangeOp = false; m_precedenceOpCount = m_nTempCom = m_nLastCom = m_nOpCode = m_openParenCount = 0; @@ -563,12 +563,12 @@ void CCalcEngine::ProcessCommandWorker(WPARAM wParam) m_nPrecOp[m_precedenceOpCount++] = 0; } - m_lastVal = Rational{}; + m_lastVal = 0; if (IsBinOpCode(m_nLastCom)) { // We want 1 + ( to start as 1 + (0. Any number you type replaces 0. But if it is 1 + 3 (, it is // treated as 1 + (3 - m_currentVal = Rational{}; + m_currentVal = 0; } m_nTempCom = 0; m_nOpCode = 0; @@ -708,7 +708,7 @@ void CCalcEngine::ProcessCommandWorker(WPARAM wParam) else { // Recall immediate memory value. - m_currentVal = Rational{ *m_memoryValue }; + m_currentVal = *m_memoryValue; } CheckAndAddLastBinOpToHistory(); DisplayNum(); @@ -734,7 +734,7 @@ void CCalcEngine::ProcessCommandWorker(WPARAM wParam) } case IDC_STORE: case IDC_MCLEAR: - m_memoryValue = make_unique(wParam == IDC_STORE ? TruncateNumForIntMath(m_currentVal) : Rational{}); + m_memoryValue = make_unique(wParam == IDC_STORE ? TruncateNumForIntMath(m_currentVal) : 0); break; case IDC_PI: @@ -1048,12 +1048,12 @@ wstring CCalcEngine::GetStringForDisplay(Rational const& rat, uint32_t radix) try { - uint64_t w64Bits = tempRat.ToUInt64_t(m_precision); + uint64_t w64Bits = tempRat.ToUInt64_t(); bool fMsb = ((w64Bits >> (m_dwWordBitWidth - 1)) & 1); if ((radix == 10) && fMsb) { // If high bit is set, then get the decimal number in negative 2's compl form. - tempRat = -(tempRat.Not(m_chopNumbers[m_numwidth], m_precision) + 1); + tempRat = -(tempRat.Not(m_chopNumbers[m_numwidth]) + 1); } result = tempRat.ToString(radix, m_nFE, m_precision); diff --git a/src/CalcManager/CEngine/scidisp.cpp b/src/CalcManager/CEngine/scidisp.cpp index aa974d8a..2784cfee 100644 --- a/src/CalcManager/CEngine/scidisp.cpp +++ b/src/CalcManager/CEngine/scidisp.cpp @@ -65,7 +65,7 @@ CalcEngine::Rational CCalcEngine::TruncateNumForIntMath(CalcEngine::Rational con { // if negative make positive by doing a twos complement result = -(result) - 1; - result = result.Not(m_chopNumbers[m_numwidth], m_precision); + result = result.Not(m_chopNumbers[m_numwidth]); } result &= m_chopNumbers[m_numwidth]; diff --git a/src/CalcManager/CEngine/scifunc.cpp b/src/CalcManager/CEngine/scifunc.cpp index f398c40d..abfd3e1b 100644 --- a/src/CalcManager/CEngine/scifunc.cpp +++ b/src/CalcManager/CEngine/scifunc.cpp @@ -53,12 +53,12 @@ CalcEngine::Rational CCalcEngine::SciCalcFunctions(CalcEngine::Rational const& r { result = Integer(rat, m_precision); - uint64_t w64Bits = result.ToUInt64_t(m_precision); + uint64_t w64Bits = result.ToUInt64_t(); uint64_t msb = (w64Bits >> (m_dwWordBitWidth - 1)) & 1; w64Bits <<= 1; // LShift by 1 w64Bits |= msb; // Set the prev Msb as the current Lsb - result = Rational{ w64Bits, m_precision }; + result = w64Bits; } break; @@ -68,12 +68,12 @@ CalcEngine::Rational CCalcEngine::SciCalcFunctions(CalcEngine::Rational const& r { result = Integer(rat, m_precision); - uint64_t w64Bits = result.ToUInt64_t(m_precision); + uint64_t w64Bits = result.ToUInt64_t(); uint64_t lsb = ((w64Bits & 0x01) == 1) ? 1 : 0; w64Bits >>= 1; //RShift by 1 w64Bits |= (lsb << (m_dwWordBitWidth - 1)); - result = Rational{ w64Bits, m_precision }; + result = w64Bits; } break; @@ -177,7 +177,7 @@ CalcEngine::Rational CCalcEngine::SciCalcFunctions(CalcEngine::Rational const& r { if (!m_fIntegerMode) { - Rational shftRat{ m_bInv ? 100 : 60 }; + auto shftRat{ m_bInv ? 100 : 60 }; Rational degreeRat = Integer(rat, m_precision); @@ -193,7 +193,7 @@ CalcEngine::Rational CCalcEngine::SciCalcFunctions(CalcEngine::Rational const& r // degreeRat == degrees, minuteRat == minutes, secondRat == seconds // - shftRat = Rational{ m_bInv ? 60 : 100 }; + shftRat = m_bInv ? 60 : 100; secondRat /= shftRat; minuteRat = (minuteRat + secondRat) / shftRat; diff --git a/src/CalcManager/CEngine/scioper.cpp b/src/CalcManager/CEngine/scioper.cpp index 6e914b51..3eac0d1d 100644 --- a/src/CalcManager/CEngine/scioper.cpp +++ b/src/CalcManager/CEngine/scioper.cpp @@ -11,7 +11,7 @@ using namespace CalcEngine::RationalMath; CalcEngine::Rational CCalcEngine::DoOperation(int operation, CalcEngine::Rational const& lhs, CalcEngine::Rational const& rhs) { // Remove any variance in how 0 could be represented in rat e.g. -0, 0/n, etc. - auto result = (!lhs.IsZero() ? lhs : Rational{}); + auto result = (!lhs.IsZero() ? lhs : 0); try { @@ -36,7 +36,7 @@ CalcEngine::Rational CCalcEngine::DoOperation(int operation, CalcEngine::Rationa throw CALC_E_NORESULT; } - uint64_t w64Bits = rhs.ToUInt64_t(m_precision); + uint64_t w64Bits = rhs.ToUInt64_t(); bool fMsb = (w64Bits >> (m_dwWordBitWidth - 1)) & 1; Rational holdVal = result; @@ -84,22 +84,22 @@ CalcEngine::Rational CCalcEngine::DoOperation(int operation, CalcEngine::Rationa if (m_fIntegerMode) { - uint64_t w64Bits = rhs.ToUInt64_t(m_precision); + uint64_t w64Bits = rhs.ToUInt64_t(); bool fMsb = (w64Bits >> (m_dwWordBitWidth - 1)) & 1; if (fMsb) { - result = rhs.Not(m_chopNumbers[m_numwidth], m_precision) + 1; + result = rhs.Not(m_chopNumbers[m_numwidth]) + 1; iNumeratorSign = -1; } - w64Bits = temp.ToUInt64_t(m_precision); + w64Bits = temp.ToUInt64_t(); fMsb = (w64Bits >> (m_dwWordBitWidth - 1)) & 1; if (fMsb) { - temp = temp.Not(m_chopNumbers[m_numwidth], m_precision) + 1; + temp = temp.Not(m_chopNumbers[m_numwidth]) + 1; iDenominatorSign = -1; } diff --git a/src/CalcManager/CEngine/sciset.cpp b/src/CalcManager/CEngine/sciset.cpp index 0078f05a..8a42ca57 100644 --- a/src/CalcManager/CEngine/sciset.cpp +++ b/src/CalcManager/CEngine/sciset.cpp @@ -18,13 +18,13 @@ void CCalcEngine::SetRadixTypeAndNumWidth(RADIX_TYPE radixtype, NUM_WIDTH numwid // back to 1111,1111,1000,0001 when in Word mode. if (m_fIntegerMode) { - uint64_t w64Bits = m_currentVal.ToUInt64_t(m_precision); + uint64_t w64Bits = m_currentVal.ToUInt64_t(); bool fMsb = (w64Bits >> (m_dwWordBitWidth - 1)) & 1; // make sure you use the old width if (fMsb) { // If high bit is set, then get the decimal number in -ve 2'scompl form. - auto tempResult = m_currentVal.Not(m_chopNumbers[m_numwidth], m_precision); + auto tempResult = m_currentVal.Not(m_chopNumbers[m_numwidth]); m_currentVal = -(tempResult + 1); } diff --git a/src/CalcManager/Header Files/Rational.h b/src/CalcManager/Header Files/Rational.h index 4e2f8097..ccd8c8b3 100644 --- a/src/CalcManager/Header Files/Rational.h +++ b/src/CalcManager/Header Files/Rational.h @@ -21,7 +21,7 @@ namespace CalcEngine Rational(Number const& p, Number const& q) noexcept; Rational(int32_t i); Rational(uint32_t ui); - Rational(uint64_t ui, int32_t precision); + Rational(uint64_t ui); explicit Rational(PRAT prat) noexcept; PRAT ToPRAT() const; @@ -56,7 +56,7 @@ namespace CalcEngine friend Rational operator|(Rational lhs, Rational const& rhs); friend Rational operator^(Rational lhs, Rational const& rhs); - Rational Not(Rational const& chopNum, int32_t precision) const; + Rational Not(Rational const& chopNum) const; bool IsZero() const; @@ -68,7 +68,7 @@ namespace CalcEngine friend bool operator>=(Rational const& lhs, Rational const& rhs); std::wstring ToString(uint32_t radix, NUMOBJ_FMT format, int32_t precision) const; - uint64_t ToUInt64_t(int32_t precision) const; + uint64_t ToUInt64_t() const; private: Number m_p;