mirror of
https://github.com/Microsoft/calculator.git
synced 2025-08-24 06:55:19 -07:00
Replace unnecessary Rational::Not with Xor operation
This commit is contained in:
parent
41db5fa28d
commit
dde5f59dc2
6 changed files with 5 additions and 12 deletions
|
@ -379,11 +379,6 @@ namespace CalcEngine
|
||||||
return lhs;
|
return lhs;
|
||||||
}
|
}
|
||||||
|
|
||||||
Rational Rational::Not(Rational const& chopNum) const
|
|
||||||
{
|
|
||||||
return *this ^ chopNum;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Rational::IsZero() const
|
bool Rational::IsZero() const
|
||||||
{
|
{
|
||||||
return this->P().IsZero();
|
return this->P().IsZero();
|
||||||
|
|
|
@ -1053,7 +1053,7 @@ wstring CCalcEngine::GetStringForDisplay(Rational const& rat, uint32_t radix)
|
||||||
if ((radix == 10) && fMsb)
|
if ((radix == 10) && fMsb)
|
||||||
{
|
{
|
||||||
// If high bit is set, then get the decimal number in negative 2's compl form.
|
// 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);
|
result = tempRat.ToString(radix, m_nFE, m_precision);
|
||||||
|
|
|
@ -65,7 +65,7 @@ CalcEngine::Rational CCalcEngine::TruncateNumForIntMath(CalcEngine::Rational con
|
||||||
{
|
{
|
||||||
// if negative make positive by doing a twos complement
|
// if negative make positive by doing a twos complement
|
||||||
result = -(result) - 1;
|
result = -(result) - 1;
|
||||||
result = result.Not(m_chopNumbers[m_numwidth]);
|
result ^= m_chopNumbers[m_numwidth];
|
||||||
}
|
}
|
||||||
|
|
||||||
result &= m_chopNumbers[m_numwidth];
|
result &= m_chopNumbers[m_numwidth];
|
||||||
|
|
|
@ -89,7 +89,7 @@ CalcEngine::Rational CCalcEngine::DoOperation(int operation, CalcEngine::Rationa
|
||||||
|
|
||||||
if (fMsb)
|
if (fMsb)
|
||||||
{
|
{
|
||||||
result = rhs.Not(m_chopNumbers[m_numwidth]) + 1;
|
result = (rhs ^ m_chopNumbers[m_numwidth]) + 1;
|
||||||
|
|
||||||
iNumeratorSign = -1;
|
iNumeratorSign = -1;
|
||||||
}
|
}
|
||||||
|
@ -99,7 +99,7 @@ CalcEngine::Rational CCalcEngine::DoOperation(int operation, CalcEngine::Rationa
|
||||||
|
|
||||||
if (fMsb)
|
if (fMsb)
|
||||||
{
|
{
|
||||||
temp = temp.Not(m_chopNumbers[m_numwidth]) + 1;
|
temp = (temp ^ m_chopNumbers[m_numwidth]) + 1;
|
||||||
|
|
||||||
iDenominatorSign = -1;
|
iDenominatorSign = -1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,7 @@ void CCalcEngine::SetRadixTypeAndNumWidth(RADIX_TYPE radixtype, NUM_WIDTH numwid
|
||||||
if (fMsb)
|
if (fMsb)
|
||||||
{
|
{
|
||||||
// If high bit is set, then get the decimal number in -ve 2'scompl form.
|
// 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);
|
m_currentVal = -(tempResult + 1);
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,8 +56,6 @@ namespace CalcEngine
|
||||||
friend Rational operator|(Rational lhs, Rational const& rhs);
|
friend Rational operator|(Rational lhs, Rational const& rhs);
|
||||||
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;
|
bool IsZero() const;
|
||||||
|
|
||||||
friend bool operator==(Rational const& lhs, Rational const& rhs);
|
friend bool operator==(Rational const& lhs, Rational const& rhs);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue