mirror of
https://github.com/Microsoft/calculator.git
synced 2025-08-22 14:13:30 -07:00
modify how we manage sign in integer mode
This commit is contained in:
parent
c546c13d0b
commit
68fbe4e6bf
1 changed files with 10 additions and 10 deletions
|
@ -78,7 +78,7 @@ CalcEngine::Rational CCalcEngine::DoOperation(int operation, CalcEngine::Rationa
|
|||
case IDC_DIV:
|
||||
case IDC_MOD:
|
||||
{
|
||||
int iNumeratorSign = 1, iDenominatorSign = 1, iFinalSign = 1;
|
||||
int iNumeratorSign = 1, iDenominatorSign = 1;
|
||||
auto temp = result;
|
||||
result = rhs;
|
||||
|
||||
|
@ -107,30 +107,30 @@ CalcEngine::Rational CCalcEngine::DoOperation(int operation, CalcEngine::Rationa
|
|||
|
||||
if (operation == IDC_DIV)
|
||||
{
|
||||
iFinalSign = iNumeratorSign * iDenominatorSign;
|
||||
result /= temp;
|
||||
if (m_fIntegerMode && (iNumeratorSign * iDenominatorSign) == -1)
|
||||
{
|
||||
result = -(Integer(result));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (m_fIntegerMode)
|
||||
{
|
||||
// Programmer mode, use remrat (remainder after division)
|
||||
iFinalSign = iNumeratorSign;
|
||||
result %= temp;
|
||||
|
||||
if (iNumeratorSign == -1)
|
||||
{
|
||||
result = -(Integer(result));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//other modes, use modrat (modulus after division)
|
||||
iFinalSign = iDenominatorSign;
|
||||
result = Mod(result, temp);
|
||||
}
|
||||
}
|
||||
|
||||
if (m_fIntegerMode && iFinalSign == -1)
|
||||
{
|
||||
result = -(Integer(result));
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue