diff --git a/src/CalcManager/CEngine/CalcUtils.cpp b/src/CalcManager/CEngine/CalcUtils.cpp
index 8807627fb..66337219c 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 6878d898d..6e004253e 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 713a661c4..64eb7f899 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 701fb21c8..6e19b1d72 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)
{
@@ -187,11 +193,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))
@@ -298,9 +320,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 42df6f7de..78ebdd7a6 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 2696181a5..6d9f1efd9 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 f387c020a..2cf8c64e1 100644
--- a/src/CalcManager/Header Files/CalcEngine.h
+++ b/src/CalcManager/Header Files/CalcEngine.h
@@ -133,6 +133,7 @@ class CCalcEngine
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 25df92bda..891226c69 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 9458f9292..bb145ad24 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
@@ -41,6 +44,30 @@ Global
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {3B773403-B0D6-4F9A-948E-512A7A5FB315}.Debug|ARM.ActiveCfg = Debug|ARM
+ {3B773403-B0D6-4F9A-948E-512A7A5FB315}.Debug|ARM.Build.0 = Debug|ARM
+ {3B773403-B0D6-4F9A-948E-512A7A5FB315}.Debug|ARM.Deploy.0 = Debug|ARM
+ {3B773403-B0D6-4F9A-948E-512A7A5FB315}.Debug|ARM64.ActiveCfg = Debug|ARM64
+ {3B773403-B0D6-4F9A-948E-512A7A5FB315}.Debug|ARM64.Build.0 = Debug|ARM64
+ {3B773403-B0D6-4F9A-948E-512A7A5FB315}.Debug|ARM64.Deploy.0 = Debug|ARM64
+ {3B773403-B0D6-4F9A-948E-512A7A5FB315}.Debug|x64.ActiveCfg = Debug|x64
+ {3B773403-B0D6-4F9A-948E-512A7A5FB315}.Debug|x64.Build.0 = Debug|x64
+ {3B773403-B0D6-4F9A-948E-512A7A5FB315}.Debug|x64.Deploy.0 = Debug|x64
+ {3B773403-B0D6-4F9A-948E-512A7A5FB315}.Debug|x86.ActiveCfg = Debug|x86
+ {3B773403-B0D6-4F9A-948E-512A7A5FB315}.Debug|x86.Build.0 = Debug|x86
+ {3B773403-B0D6-4F9A-948E-512A7A5FB315}.Debug|x86.Deploy.0 = Debug|x86
+ {3B773403-B0D6-4F9A-948E-512A7A5FB315}.Release|ARM.ActiveCfg = Release|ARM
+ {3B773403-B0D6-4F9A-948E-512A7A5FB315}.Release|ARM.Build.0 = Release|ARM
+ {3B773403-B0D6-4F9A-948E-512A7A5FB315}.Release|ARM.Deploy.0 = Release|ARM
+ {3B773403-B0D6-4F9A-948E-512A7A5FB315}.Release|ARM64.ActiveCfg = Release|ARM64
+ {3B773403-B0D6-4F9A-948E-512A7A5FB315}.Release|ARM64.Build.0 = Release|ARM64
+ {3B773403-B0D6-4F9A-948E-512A7A5FB315}.Release|ARM64.Deploy.0 = Release|ARM64
+ {3B773403-B0D6-4F9A-948E-512A7A5FB315}.Release|x64.ActiveCfg = Release|x64
+ {3B773403-B0D6-4F9A-948E-512A7A5FB315}.Release|x64.Build.0 = Release|x64
+ {3B773403-B0D6-4F9A-948E-512A7A5FB315}.Release|x64.Deploy.0 = Release|x64
+ {3B773403-B0D6-4F9A-948E-512A7A5FB315}.Release|x86.ActiveCfg = Release|x86
+ {3B773403-B0D6-4F9A-948E-512A7A5FB315}.Release|x86.Build.0 = Release|x86
+ {3B773403-B0D6-4F9A-948E-512A7A5FB315}.Release|x86.Deploy.0 = Release|x86
{311E866D-8B93-4609-A691-265941FEE101}.Debug|ARM.ActiveCfg = Debug|ARM
{311E866D-8B93-4609-A691-265941FEE101}.Debug|ARM.Build.0 = Debug|ARM
{311E866D-8B93-4609-A691-265941FEE101}.Debug|ARM64.ActiveCfg = Debug|ARM64
@@ -169,30 +196,6 @@ Global
{FC81FF41-02CD-4CD9-9BC5-45A1E39AC6ED}.Release|x64.Build.0 = Release|x64
{FC81FF41-02CD-4CD9-9BC5-45A1E39AC6ED}.Release|x86.ActiveCfg = Release|Win32
{FC81FF41-02CD-4CD9-9BC5-45A1E39AC6ED}.Release|x86.Build.0 = Release|Win32
- {3B773403-B0D6-4F9A-948E-512A7A5FB315}.Debug|ARM.ActiveCfg = Debug|ARM
- {3B773403-B0D6-4F9A-948E-512A7A5FB315}.Debug|ARM.Build.0 = Debug|ARM
- {3B773403-B0D6-4F9A-948E-512A7A5FB315}.Debug|ARM.Deploy.0 = Debug|ARM
- {3B773403-B0D6-4F9A-948E-512A7A5FB315}.Debug|ARM64.ActiveCfg = Debug|ARM64
- {3B773403-B0D6-4F9A-948E-512A7A5FB315}.Debug|ARM64.Build.0 = Debug|ARM64
- {3B773403-B0D6-4F9A-948E-512A7A5FB315}.Debug|ARM64.Deploy.0 = Debug|ARM64
- {3B773403-B0D6-4F9A-948E-512A7A5FB315}.Debug|x64.ActiveCfg = Debug|x64
- {3B773403-B0D6-4F9A-948E-512A7A5FB315}.Debug|x64.Build.0 = Debug|x64
- {3B773403-B0D6-4F9A-948E-512A7A5FB315}.Debug|x64.Deploy.0 = Debug|x64
- {3B773403-B0D6-4F9A-948E-512A7A5FB315}.Debug|x86.ActiveCfg = Debug|x86
- {3B773403-B0D6-4F9A-948E-512A7A5FB315}.Debug|x86.Build.0 = Debug|x86
- {3B773403-B0D6-4F9A-948E-512A7A5FB315}.Debug|x86.Deploy.0 = Debug|x86
- {3B773403-B0D6-4F9A-948E-512A7A5FB315}.Release|ARM.ActiveCfg = Release|ARM
- {3B773403-B0D6-4F9A-948E-512A7A5FB315}.Release|ARM.Build.0 = Release|ARM
- {3B773403-B0D6-4F9A-948E-512A7A5FB315}.Release|ARM.Deploy.0 = Release|ARM
- {3B773403-B0D6-4F9A-948E-512A7A5FB315}.Release|ARM64.ActiveCfg = Release|ARM64
- {3B773403-B0D6-4F9A-948E-512A7A5FB315}.Release|ARM64.Build.0 = Release|ARM64
- {3B773403-B0D6-4F9A-948E-512A7A5FB315}.Release|ARM64.Deploy.0 = Release|ARM64
- {3B773403-B0D6-4F9A-948E-512A7A5FB315}.Release|x64.ActiveCfg = Release|x64
- {3B773403-B0D6-4F9A-948E-512A7A5FB315}.Release|x64.Build.0 = Release|x64
- {3B773403-B0D6-4F9A-948E-512A7A5FB315}.Release|x64.Deploy.0 = Release|x64
- {3B773403-B0D6-4F9A-948E-512A7A5FB315}.Release|x86.ActiveCfg = Release|x86
- {3B773403-B0D6-4F9A-948E-512A7A5FB315}.Release|x86.Build.0 = Release|x86
- {3B773403-B0D6-4F9A-948E-512A7A5FB315}.Release|x86.Deploy.0 = Release|x86
{CC9B4FA7-D746-4F52-9401-0AD1B4D6B16D}.Debug|ARM.ActiveCfg = Debug|ARM
{CC9B4FA7-D746-4F52-9401-0AD1B4D6B16D}.Debug|ARM.Build.0 = Debug|ARM
{CC9B4FA7-D746-4F52-9401-0AD1B4D6B16D}.Debug|ARM64.ActiveCfg = Debug|ARM64