modify how we manage sign in integer mode

This commit is contained in:
Rudy Huyn 2019-04-01 00:17:19 -07:00
commit 68fbe4e6bf

View file

@ -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;
}