diff --git a/src/CalcManager/CEngine/CalcUtils.cpp b/src/CalcManager/CEngine/CalcUtils.cpp index 8807627f..66337219 100644 --- a/src/CalcManager/CEngine/CalcUtils.cpp +++ b/src/CalcManager/CEngine/CalcUtils.cpp @@ -44,7 +44,6 @@ bool IsGuiSettingOpCode(OpCode opCode) case IDC_FE: case IDC_MCLEAR: case IDC_BACK: - case IDC_EXP: case IDC_STORE: case IDC_MPLUS: case IDC_MMINUS: diff --git a/src/CalcManager/CEngine/Rational.cpp b/src/CalcManager/CEngine/Rational.cpp index 6878d898..6e004253 100644 --- a/src/CalcManager/CEngine/Rational.cpp +++ b/src/CalcManager/CEngine/Rational.cpp @@ -87,6 +87,11 @@ namespace CalcEngine return m_q; } + bool Rational::IsZero() const + { + return m_p.IsZero(); + } + Rational Rational::operator-() const { return Rational{ Number{ -1 * m_p.Sign(), m_p.Exp(), m_p.Mantissa() }, m_q }; diff --git a/src/CalcManager/CEngine/calc.cpp b/src/CalcManager/CEngine/calc.cpp index 7ef2acb7..b931cfcf 100644 --- a/src/CalcManager/CEngine/calc.cpp +++ b/src/CalcManager/CEngine/calc.cpp @@ -71,6 +71,7 @@ CCalcEngine::CCalcEngine( , m_nPrevOpCode(0) , m_bChangeOp(false) , m_bRecord(false) + , m_bFlagSign(false) , m_bSetCalcState(false) , m_input(DEFAULT_DEC_SEPARATOR) , m_nFE(NumberFormat::Float) diff --git a/src/CalcManager/CEngine/scicomm.cpp b/src/CalcManager/CEngine/scicomm.cpp index a4300edc..0f6cf7d0 100644 --- a/src/CalcManager/CEngine/scicomm.cpp +++ b/src/CalcManager/CEngine/scicomm.cpp @@ -112,10 +112,11 @@ void CCalcEngine::ProcessCommandWorker(OpCode wParam) { // Save the last command. Some commands are not saved in this manor, these // commands are: - // Inv, Deg, Rad, Grad, Stat, FE, MClear, Back, and Exp. The excluded + // Inv, Deg, Rad, Grad, Stat, FE, MClear, and Back. The excluded // commands are not // really mathematical operations, rather they are GUI mode settings. - + // + // UDATE: We now save the last command for the Exp command as well. if (!IsGuiSettingOpCode(wParam)) { m_nLastCom = m_nTempCom; @@ -146,6 +147,11 @@ void CCalcEngine::ProcessCommandWorker(OpCode wParam) } } + if (wParam == IDC_SUB && m_nLastCom == IDC_EXP) + { + wParam = IDC_SIGN; + } + // Toggle Record/Display mode if appropriate. if (m_bRecord) { @@ -227,11 +233,27 @@ void CCalcEngine::ProcessCommandWorker(OpCode wParam) } DisplayNum(); - return; + /* + Addressing issues: + #1541 https://github.com/microsoft/calculator/issues/1541 + #1311 https://github.com/microsoft/calculator/issues/1311 + Solution: + Consider the previous '-' Binary Op as a '+/-' sign value if + the first opnd is 0. + */ + if (m_bFlagSign) + { + wParam = IDC_SIGN; + m_bFlagSign = false; + } + else + { + return; + } } // BINARY OPERATORS: - if (IsBinOpCode(wParam)) + if (IsBinOpCode(wParam)) { // Change the operation if last input was operation. if (IsBinOpCode(m_nLastCom)) @@ -338,9 +360,19 @@ void CCalcEngine::ProcessCommandWorker(OpCode wParam) } DisplayAnnounceBinaryOperator(); + + // consider this sub as +/- for the upcoming number + if ( wParam == IDC_SUB && m_currentVal.IsZero()) + { + m_bFlagSign = true; + } + m_lastVal = m_currentVal; m_nOpCode = (int)wParam; - m_HistoryCollector.AddBinOpToHistory(m_nOpCode, m_fIntegerMode); + if (!m_bFlagSign) + { + m_HistoryCollector.AddBinOpToHistory(m_nOpCode, m_fIntegerMode); + } m_bNoPrevEqu = m_bChangeOp = true; return; } diff --git a/src/CalcManager/CalcManager.vcxproj b/src/CalcManager/CalcManager.vcxproj index e47cea17..63ee5ff0 100644 --- a/src/CalcManager/CalcManager.vcxproj +++ b/src/CalcManager/CalcManager.vcxproj @@ -131,7 +131,9 @@ - + + $(SolutionDir)$(Platform)\$(Configuration)\Calculator + false true @@ -217,6 +219,7 @@ Level4 true pch.h + ProgramDatabase Console diff --git a/src/CalcManager/Header Files/CCommand.h b/src/CalcManager/Header Files/CCommand.h index 2696181a..6d9f1efd 100644 --- a/src/CalcManager/Header Files/CCommand.h +++ b/src/CalcManager/Header Files/CCommand.h @@ -115,8 +115,8 @@ #define IDC_EXP 127 -#define IDC_OPENP 128 -#define IDC_CLOSEP 129 +#define IDC_OPENP 128 // Open parenthesis "(" +#define IDC_CLOSEP 129 // Close parenthesis ")" #define IDC_0 130 // The controls for 0 through F must be consecutive and in order #define IDC_1 131 diff --git a/src/CalcManager/Header Files/CalcEngine.h b/src/CalcManager/Header Files/CalcEngine.h index eaa2956b..91d36735 100644 --- a/src/CalcManager/Header Files/CalcEngine.h +++ b/src/CalcManager/Header Files/CalcEngine.h @@ -135,6 +135,7 @@ private: bool m_bError; // Error flag. bool m_bInv; // Inverse on/off flag. bool m_bNoPrevEqu; /* Flag for previous equals. */ + bool m_bFlagSign; /* Flag for +/- on next op */ uint32_t m_radix; int32_t m_precision; diff --git a/src/CalcManager/Header Files/Rational.h b/src/CalcManager/Header Files/Rational.h index 25df92bd..891226c6 100644 --- a/src/CalcManager/Header Files/Rational.h +++ b/src/CalcManager/Header Files/Rational.h @@ -30,6 +30,8 @@ namespace CalcEngine Number const& P() const; Number const& Q() const; + bool IsZero() const; + Rational operator-() const; Rational& operator+=(Rational const& rhs); Rational& operator-=(Rational const& rhs); diff --git a/src/Calculator.sln b/src/Calculator.sln index 4e53844c..a86402bc 100644 --- a/src/Calculator.sln +++ b/src/Calculator.sln @@ -10,6 +10,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution EndProjectSection EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Calculator", "Calculator\Calculator.csproj", "{3B773403-B0D6-4F9A-948E-512A7A5FB315}" + ProjectSection(ProjectDependencies) = postProject + {311E866D-8B93-4609-A691-265941FEE101} = {311E866D-8B93-4609-A691-265941FEE101} + EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CalcManager", "CalcManager\CalcManager.vcxproj", "{311E866D-8B93-4609-A691-265941FEE101}" EndProject