mirror of
https://github.com/Microsoft/calculator.git
synced 2025-08-22 06:13:14 -07:00
Convert Rational::Mod to use %= and % operator overrides
This commit is contained in:
parent
09d8e60798
commit
34b27977f6
3 changed files with 29 additions and 22 deletions
|
@ -183,6 +183,29 @@ namespace CalcEngine
|
|||
return *this;
|
||||
}
|
||||
|
||||
Rational& Rational::operator%=(Rational const& rhs)
|
||||
{
|
||||
PRAT lhsRat = this->ToPRAT();
|
||||
PRAT rhsRat = rhs.ToPRAT();
|
||||
|
||||
try
|
||||
{
|
||||
modrat(&lhsRat, rhsRat);
|
||||
destroyrat(rhsRat);
|
||||
}
|
||||
catch (DWORD error)
|
||||
{
|
||||
destroyrat(lhsRat);
|
||||
destroyrat(rhsRat);
|
||||
throw(error);
|
||||
}
|
||||
|
||||
*this = Rational{ lhsRat };
|
||||
destroyrat(lhsRat);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
Rational operator+(Rational lhs, Rational const& rhs)
|
||||
{
|
||||
lhs += rhs;
|
||||
|
@ -207,27 +230,10 @@ namespace CalcEngine
|
|||
return lhs;
|
||||
}
|
||||
|
||||
Rational Rational::Mod(Rational const& rhs) const
|
||||
Rational operator%(Rational lhs, Rational const& rhs)
|
||||
{
|
||||
PRAT lhsRat = this->ToPRAT();
|
||||
PRAT rhsRat = rhs.ToPRAT();
|
||||
|
||||
try
|
||||
{
|
||||
modrat(&lhsRat, rhsRat);
|
||||
destroyrat(rhsRat);
|
||||
}
|
||||
catch (DWORD error)
|
||||
{
|
||||
destroyrat(lhsRat);
|
||||
destroyrat(rhsRat);
|
||||
throw(error);
|
||||
}
|
||||
|
||||
Rational result = Rational{ lhsRat };
|
||||
destroyrat(lhsRat);
|
||||
|
||||
return result;
|
||||
lhs %= rhs;
|
||||
return lhs;
|
||||
}
|
||||
|
||||
Rational Rational::Lsh(Rational const& rhs, int32_t precision) const
|
||||
|
|
|
@ -114,7 +114,7 @@ CalcEngine::Rational CCalcEngine::DoOperation(int operation, CalcEngine::Rationa
|
|||
else
|
||||
{
|
||||
iFinalSign = iNumeratorSign;
|
||||
result = result.Mod(temp);
|
||||
result %= temp;
|
||||
}
|
||||
|
||||
if (m_fIntegerMode && iFinalSign == -1)
|
||||
|
|
|
@ -34,12 +34,13 @@ namespace CalcEngine
|
|||
Rational& operator-=(Rational const& rhs);
|
||||
Rational& operator*=(Rational const& rhs);
|
||||
Rational& operator/=(Rational const& rhs);
|
||||
Rational Mod(Rational const& rhs) const;
|
||||
Rational& operator%=(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);
|
||||
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