mirror of
https://github.com/Microsoft/calculator.git
synced 2025-08-23 06:25:19 -07:00
Fix:The application displays faulty results with unary operations when a binary action was previously used
This commit is contained in:
parent
9515544c25
commit
ae163c8067
1 changed files with 45 additions and 6 deletions
|
@ -170,6 +170,8 @@ void CCalcEngine::ProcessCommandWorker(OpCode wParam)
|
||||||
// BINARY OPERATORS:
|
// BINARY OPERATORS:
|
||||||
if (IsBinOpCode(wParam))
|
if (IsBinOpCode(wParam))
|
||||||
{
|
{
|
||||||
|
m_bNoPrevEqu = true;
|
||||||
|
|
||||||
// Change the operation if last input was operation.
|
// Change the operation if last input was operation.
|
||||||
if (IsBinOpCode(m_nLastCom))
|
if (IsBinOpCode(m_nLastCom))
|
||||||
{
|
{
|
||||||
|
@ -274,13 +276,18 @@ void CCalcEngine::ProcessCommandWorker(OpCode wParam)
|
||||||
m_lastVal = m_currentVal;
|
m_lastVal = m_currentVal;
|
||||||
m_nOpCode = (int)wParam;
|
m_nOpCode = (int)wParam;
|
||||||
m_HistoryCollector.AddBinOpToHistory(m_nOpCode);
|
m_HistoryCollector.AddBinOpToHistory(m_nOpCode);
|
||||||
m_bNoPrevEqu = m_bChangeOp = true;
|
m_bChangeOp = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// UNARY OPERATORS:
|
// UNARY OPERATORS:
|
||||||
if (IsUnaryOpCode(wParam) || (wParam == IDC_DEGREES))
|
if (IsUnaryOpCode(wParam) || (wParam == IDC_DEGREES))
|
||||||
{
|
{
|
||||||
|
m_bNoPrevEqu = true;
|
||||||
|
m_bChangeOp = false;
|
||||||
|
m_nPrevOpCode = m_nOpCode;
|
||||||
|
m_nOpCode = (INT)wParam;
|
||||||
|
|
||||||
/* Functions are unary operations. */
|
/* Functions are unary operations. */
|
||||||
/* If the last thing done was an operator, m_currentVal was cleared. */
|
/* If the last thing done was an operator, m_currentVal was cleared. */
|
||||||
/* In that case we better use the number before the operator */
|
/* In that case we better use the number before the operator */
|
||||||
|
@ -642,7 +649,11 @@ void CCalcEngine::ProcessCommandWorker(OpCode wParam)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_nOpCode = IDC_SIGN;
|
||||||
|
m_bNoPrevEqu = true;
|
||||||
|
}
|
||||||
// Doing +/- while in Record mode is not a unary operation
|
// Doing +/- while in Record mode is not a unary operation
|
||||||
if (IsBinOpCode(m_nLastCom))
|
if (IsBinOpCode(m_nLastCom))
|
||||||
{
|
{
|
||||||
|
@ -655,7 +666,6 @@ void CCalcEngine::ProcessCommandWorker(OpCode wParam)
|
||||||
}
|
}
|
||||||
|
|
||||||
m_currentVal = -(m_currentVal);
|
m_currentVal = -(m_currentVal);
|
||||||
|
|
||||||
DisplayNum();
|
DisplayNum();
|
||||||
m_HistoryCollector.AddUnaryOpToHistory(IDC_SIGN, m_bInv, m_angletype);
|
m_HistoryCollector.AddUnaryOpToHistory(IDC_SIGN, m_bInv, m_angletype);
|
||||||
}
|
}
|
||||||
|
@ -701,6 +711,13 @@ void CCalcEngine::ProcessCommandWorker(OpCode wParam)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case IDC_PI:
|
case IDC_PI:
|
||||||
|
|
||||||
|
m_bNoPrevEqu = true;
|
||||||
|
if (!m_bChangeOp)
|
||||||
|
{
|
||||||
|
m_nOpCode = 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (!m_fIntegerMode)
|
if (!m_fIntegerMode)
|
||||||
{
|
{
|
||||||
CheckAndAddLastBinOpToHistory(); // pi is like entering the number
|
CheckAndAddLastBinOpToHistory(); // pi is like entering the number
|
||||||
|
@ -760,12 +777,34 @@ void CCalcEngine::ResolveHighestPrecedenceOperation()
|
||||||
{
|
{
|
||||||
m_currentVal = m_holdVal;
|
m_currentVal = m_holdVal;
|
||||||
DisplayNum(); // to update the m_numberString
|
DisplayNum(); // to update the m_numberString
|
||||||
m_HistoryCollector.AddBinOpToHistory(m_nOpCode, false);
|
if (IsBinOpCode(m_nOpCode))
|
||||||
m_HistoryCollector.AddOpndToHistory(m_numberString, m_currentVal); // Adding the repeated last op to history
|
{
|
||||||
|
m_HistoryCollector.AddBinOpToHistory(m_nOpCode, false);
|
||||||
|
m_HistoryCollector.AddOpndToHistory(m_numberString, m_currentVal); // Adding the repeated last op to history
|
||||||
|
}
|
||||||
|
else if (m_nOpCode == IDC_SIGN || IsUnaryOpCode(m_nOpCode))
|
||||||
|
{
|
||||||
|
m_HistoryCollector.AddUnaryOpToHistory(m_nOpCode, m_bInv, m_angletype);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Do the current or last operation.
|
// Do the current or last operation.
|
||||||
m_currentVal = DoOperation(m_nOpCode, m_currentVal, m_lastVal);
|
if (!m_bNoPrevEqu && (m_nOpCode == IDC_SIGN || IsUnaryOpCode(m_nOpCode)))
|
||||||
|
{
|
||||||
|
if (m_nOpCode == IDC_SIGN)
|
||||||
|
{
|
||||||
|
m_currentVal = -m_currentVal;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_currentVal = SciCalcFunctions(m_currentVal, (DWORD)m_nOpCode);
|
||||||
|
}
|
||||||
|
m_holdVal = m_currentVal;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_currentVal = DoOperation(m_nOpCode, m_currentVal, m_lastVal);
|
||||||
|
}
|
||||||
m_nPrevOpCode = m_nOpCode;
|
m_nPrevOpCode = m_nOpCode;
|
||||||
m_lastVal = m_currentVal;
|
m_lastVal = m_currentVal;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue