mirror of
https://github.com/Microsoft/calculator.git
synced 2025-08-21 22:03:11 -07:00
Convet Rational::Sub to - and -= operator overrides.
This commit is contained in:
parent
259d16e1b8
commit
4961b7c967
6 changed files with 23 additions and 17 deletions
|
@ -114,20 +114,14 @@ namespace CalcEngine
|
|||
return *this;
|
||||
}
|
||||
|
||||
Rational operator+(Rational lhs, Rational const& rhs)
|
||||
{
|
||||
lhs += rhs;
|
||||
return lhs;
|
||||
}
|
||||
|
||||
Rational Rational::Sub(Rational const& rhs, int32_t precision) const
|
||||
Rational& Rational::operator-=(Rational const& rhs)
|
||||
{
|
||||
PRAT lhsRat = this->ToPRAT();
|
||||
PRAT rhsRat = rhs.ToPRAT();
|
||||
|
||||
try
|
||||
{
|
||||
subrat(&lhsRat, rhsRat, precision);
|
||||
subrat(&lhsRat, rhsRat, RATIONAL_PRECISION);
|
||||
destroyrat(rhsRat);
|
||||
}
|
||||
catch (DWORD error)
|
||||
|
@ -137,10 +131,22 @@ namespace CalcEngine
|
|||
throw(error);
|
||||
}
|
||||
|
||||
Rational result = Rational{ lhsRat };
|
||||
*this = Rational{ lhsRat };
|
||||
destroyrat(lhsRat);
|
||||
|
||||
return result;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Rational operator+(Rational lhs, Rational const& rhs)
|
||||
{
|
||||
lhs += rhs;
|
||||
return lhs;
|
||||
}
|
||||
|
||||
Rational operator-(Rational lhs, Rational const& rhs)
|
||||
{
|
||||
lhs -= rhs;
|
||||
return lhs;
|
||||
}
|
||||
|
||||
Rational Rational::Mul(Rational const& rhs, int32_t precision) const
|
||||
|
|
|
@ -727,7 +727,7 @@ void CCalcEngine::ProcessCommandWorker(WPARAM wParam)
|
|||
{
|
||||
/* MMINUS subtracts m_currentVal to immediate memory and kills the "mem" */
|
||||
/* indicator if the result is zero. */
|
||||
Rational result = m_memoryValue->Sub(m_currentVal, m_precision);
|
||||
Rational result = *m_memoryValue - m_currentVal;
|
||||
m_memoryValue = make_unique<Rational>(TruncateNumForIntMath(result));
|
||||
|
||||
break;
|
||||
|
|
|
@ -64,8 +64,7 @@ CalcEngine::Rational CCalcEngine::TruncateNumForIntMath(CalcEngine::Rational con
|
|||
if (result.IsLess(0, m_precision))
|
||||
{
|
||||
// if negative make positive by doing a twos complement
|
||||
result = -(result);
|
||||
result = result.Sub(1, m_precision);
|
||||
result = -(result) - 1;
|
||||
result = result.Not(m_chopNumbers[m_numwidth], m_precision);
|
||||
}
|
||||
|
||||
|
|
|
@ -182,14 +182,14 @@ CalcEngine::Rational CCalcEngine::SciCalcFunctions(CalcEngine::Rational const& r
|
|||
|
||||
Rational degreeRat = Integer(rat, m_precision);
|
||||
|
||||
Rational minuteRat = rat.Sub(degreeRat, m_precision);
|
||||
Rational minuteRat = rat - degreeRat;
|
||||
minuteRat = minuteRat.Mul(shftRat, m_precision);
|
||||
|
||||
Rational secondRat = minuteRat;
|
||||
|
||||
minuteRat = Integer(minuteRat, m_precision);
|
||||
|
||||
secondRat = secondRat.Sub(minuteRat, m_precision);
|
||||
secondRat -= minuteRat;
|
||||
secondRat = secondRat.Mul(shftRat, m_precision);
|
||||
|
||||
//
|
||||
|
|
|
@ -69,7 +69,7 @@ CalcEngine::Rational CCalcEngine::DoOperation(int operation, CalcEngine::Rationa
|
|||
break;
|
||||
|
||||
case IDC_SUB:
|
||||
result = rhs.Sub(result, m_precision);
|
||||
result = rhs - result;
|
||||
break;
|
||||
|
||||
case IDC_MUL:
|
||||
|
|
|
@ -31,12 +31,13 @@ namespace CalcEngine
|
|||
|
||||
Rational operator-() const;
|
||||
Rational& operator+=(Rational const& rhs);
|
||||
Rational Sub(Rational const& rhs, int32_t precision) const;
|
||||
Rational& operator-=(Rational const& rhs);
|
||||
Rational Mul(Rational const& rhs, int32_t precision) const;
|
||||
Rational Div(Rational const& rhs, int32_t precision) const;
|
||||
Rational Mod(Rational const& rhs) const;
|
||||
|
||||
friend Rational operator+(Rational lhs, Rational const& rhs);
|
||||
friend Rational operator-(Rational lhs, Rational const& rhs);
|
||||
|
||||
Rational Lsh(Rational const& r, int32_t precision) const;
|
||||
Rational Rsh(Rational const& r, int32_t precision) const;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue