Replace unnecessary Rational::Not with Xor operation

This commit is contained in:
Josh Koon 2019-02-21 16:47:14 -08:00
commit dde5f59dc2
6 changed files with 5 additions and 12 deletions

View file

@ -379,11 +379,6 @@ namespace CalcEngine
return lhs;
}
Rational Rational::Not(Rational const& chopNum) const
{
return *this ^ chopNum;
}
bool Rational::IsZero() const
{
return this->P().IsZero();

View file

@ -1053,7 +1053,7 @@ wstring CCalcEngine::GetStringForDisplay(Rational const& rat, uint32_t radix)
if ((radix == 10) && fMsb)
{
// If high bit is set, then get the decimal number in negative 2's compl form.
tempRat = -(tempRat.Not(m_chopNumbers[m_numwidth]) + 1);
tempRat = -((tempRat ^ m_chopNumbers[m_numwidth]) + 1);
}
result = tempRat.ToString(radix, m_nFE, m_precision);

View file

@ -65,7 +65,7 @@ CalcEngine::Rational CCalcEngine::TruncateNumForIntMath(CalcEngine::Rational con
{
// if negative make positive by doing a twos complement
result = -(result) - 1;
result = result.Not(m_chopNumbers[m_numwidth]);
result ^= m_chopNumbers[m_numwidth];
}
result &= m_chopNumbers[m_numwidth];

View file

@ -89,7 +89,7 @@ CalcEngine::Rational CCalcEngine::DoOperation(int operation, CalcEngine::Rationa
if (fMsb)
{
result = rhs.Not(m_chopNumbers[m_numwidth]) + 1;
result = (rhs ^ m_chopNumbers[m_numwidth]) + 1;
iNumeratorSign = -1;
}
@ -99,7 +99,7 @@ CalcEngine::Rational CCalcEngine::DoOperation(int operation, CalcEngine::Rationa
if (fMsb)
{
temp = temp.Not(m_chopNumbers[m_numwidth]) + 1;
temp = (temp ^ m_chopNumbers[m_numwidth]) + 1;
iDenominatorSign = -1;
}

View file

@ -24,7 +24,7 @@ void CCalcEngine::SetRadixTypeAndNumWidth(RADIX_TYPE radixtype, NUM_WIDTH numwid
if (fMsb)
{
// If high bit is set, then get the decimal number in -ve 2'scompl form.
auto tempResult = m_currentVal.Not(m_chopNumbers[m_numwidth]);
auto tempResult = m_currentVal ^ m_chopNumbers[m_numwidth];
m_currentVal = -(tempResult + 1);
}

View file

@ -56,8 +56,6 @@ namespace CalcEngine
friend Rational operator|(Rational lhs, Rational const& rhs);
friend Rational operator^(Rational lhs, Rational const& rhs);
Rational Not(Rational const& chopNum) const;
bool IsZero() const;
friend bool operator==(Rational const& lhs, Rational const& rhs);