mirror of
https://github.com/Microsoft/calculator.git
synced 2025-08-22 14:13:30 -07:00
rational functions now using shared_ptr spawned in ToSmartRat
This commit is contained in:
parent
2d4f57f6dd
commit
80d9d1d42b
2 changed files with 33 additions and 22 deletions
|
@ -71,6 +71,16 @@ namespace CalcEngine
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
shared_ptr<RAT> Rational::ToSmartRAT() const
|
||||||
|
{
|
||||||
|
shared_ptr<RAT> smartRat(_createrat(), &_destroyrat);
|
||||||
|
|
||||||
|
smartRat.get()->pp = this->P().ToPNUMBER();
|
||||||
|
smartRat.get()->pq = this->Q().ToPNUMBER();
|
||||||
|
|
||||||
|
return smartRat;
|
||||||
|
}
|
||||||
|
|
||||||
Number const& Rational::P() const
|
Number const& Rational::P() const
|
||||||
{
|
{
|
||||||
return m_p;
|
return m_p;
|
||||||
|
@ -128,9 +138,9 @@ namespace CalcEngine
|
||||||
|
|
||||||
Rational& Rational::operator*=(Rational const& rhs)
|
Rational& Rational::operator*=(Rational const& rhs)
|
||||||
{
|
{
|
||||||
unique_ptr<RAT, decltype(&_destroyrat)> lhsSmartRat(this->ToPRAT(), &_destroyrat);
|
shared_ptr<RAT> lhsSmartRat = this->ToSmartRAT();
|
||||||
auto lhsPrat = lhsSmartRat.get();
|
auto lhsPrat = lhsSmartRat.get();
|
||||||
unique_ptr<RAT, decltype(&_destroyrat)> rhsSmartRat(rhs.ToPRAT(), &_destroyrat);
|
shared_ptr<RAT> rhsSmartRat = rhs.ToSmartRAT();
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -148,9 +158,9 @@ namespace CalcEngine
|
||||||
|
|
||||||
Rational& Rational::operator/=(Rational const& rhs)
|
Rational& Rational::operator/=(Rational const& rhs)
|
||||||
{
|
{
|
||||||
unique_ptr<RAT, decltype(&_destroyrat)> lhsSmartRat(this->ToPRAT(), &_destroyrat);
|
shared_ptr<RAT> lhsSmartRat = this->ToSmartRAT();
|
||||||
auto lhsPrat = lhsSmartRat.get();
|
auto lhsPrat = lhsSmartRat.get();
|
||||||
unique_ptr<RAT, decltype(&_destroyrat)> rhsSmartRat(rhs.ToPRAT(), &_destroyrat);
|
shared_ptr<RAT> rhsSmartRat = rhs.ToSmartRAT();
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -168,9 +178,9 @@ namespace CalcEngine
|
||||||
|
|
||||||
Rational& Rational::operator%=(Rational const& rhs)
|
Rational& Rational::operator%=(Rational const& rhs)
|
||||||
{
|
{
|
||||||
unique_ptr<RAT, decltype(&_destroyrat)> lhsSmartRat(this->ToPRAT(), &_destroyrat);
|
shared_ptr<RAT> lhsSmartRat = this->ToSmartRAT();
|
||||||
auto lhsPrat = lhsSmartRat.get();
|
auto lhsPrat = lhsSmartRat.get();
|
||||||
unique_ptr<RAT, decltype(&_destroyrat)> rhsSmartRat(rhs.ToPRAT(), &_destroyrat);
|
shared_ptr<RAT> rhsSmartRat = rhs.ToSmartRAT();
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -188,9 +198,9 @@ namespace CalcEngine
|
||||||
|
|
||||||
Rational& Rational::operator<<=(Rational const& rhs)
|
Rational& Rational::operator<<=(Rational const& rhs)
|
||||||
{
|
{
|
||||||
unique_ptr<RAT, decltype(&_destroyrat)> lhsSmartRat(this->ToPRAT(), &_destroyrat);
|
shared_ptr<RAT> lhsSmartRat = this->ToSmartRAT();
|
||||||
auto lhsPrat = lhsSmartRat.get();
|
auto lhsPrat = lhsSmartRat.get();
|
||||||
unique_ptr<RAT, decltype(&_destroyrat)> rhsSmartRat(rhs.ToPRAT(), &_destroyrat);
|
shared_ptr<RAT> rhsSmartRat = rhs.ToSmartRAT();
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -208,9 +218,9 @@ namespace CalcEngine
|
||||||
|
|
||||||
Rational& Rational::operator>>=(Rational const& rhs)
|
Rational& Rational::operator>>=(Rational const& rhs)
|
||||||
{
|
{
|
||||||
unique_ptr<RAT, decltype(&_destroyrat)> lhsSmartRat(this->ToPRAT(), &_destroyrat);
|
shared_ptr<RAT> lhsSmartRat = this->ToSmartRAT();
|
||||||
auto lhsPrat = lhsSmartRat.get();
|
auto lhsPrat = lhsSmartRat.get();
|
||||||
unique_ptr<RAT, decltype(&_destroyrat)> rhsSmartRat(rhs.ToPRAT(), &_destroyrat);
|
shared_ptr<RAT> rhsSmartRat = rhs.ToSmartRAT();
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -228,9 +238,9 @@ namespace CalcEngine
|
||||||
|
|
||||||
Rational& Rational::operator&=(Rational const& rhs)
|
Rational& Rational::operator&=(Rational const& rhs)
|
||||||
{
|
{
|
||||||
unique_ptr<RAT, decltype(&_destroyrat)> lhsSmartRat(this->ToPRAT(), &_destroyrat);
|
shared_ptr<RAT> lhsSmartRat = this->ToSmartRAT();
|
||||||
auto lhsPrat = lhsSmartRat.get();
|
auto lhsPrat = lhsSmartRat.get();
|
||||||
unique_ptr<RAT, decltype(&_destroyrat)> rhsSmartRat(rhs.ToPRAT(), &_destroyrat);
|
shared_ptr<RAT> rhsSmartRat = rhs.ToSmartRAT();
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -248,9 +258,9 @@ namespace CalcEngine
|
||||||
|
|
||||||
Rational& Rational::operator|=(Rational const& rhs)
|
Rational& Rational::operator|=(Rational const& rhs)
|
||||||
{
|
{
|
||||||
unique_ptr<RAT, decltype(&_destroyrat)> lhsSmartRat(this->ToPRAT(), &_destroyrat);
|
shared_ptr<RAT> lhsSmartRat = this->ToSmartRAT();
|
||||||
auto lhsPrat = lhsSmartRat.get();
|
auto lhsPrat = lhsSmartRat.get();
|
||||||
unique_ptr<RAT, decltype(&_destroyrat)> rhsSmartRat(rhs.ToPRAT(), &_destroyrat);
|
shared_ptr<RAT> rhsSmartRat = rhs.ToSmartRAT();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
orrat(&lhsPrat, rhsSmartRat.get(), RATIONAL_BASE, RATIONAL_PRECISION);
|
orrat(&lhsPrat, rhsSmartRat.get(), RATIONAL_BASE, RATIONAL_PRECISION);
|
||||||
|
@ -267,9 +277,9 @@ namespace CalcEngine
|
||||||
|
|
||||||
Rational& Rational::operator^=(Rational const& rhs)
|
Rational& Rational::operator^=(Rational const& rhs)
|
||||||
{
|
{
|
||||||
unique_ptr<RAT, decltype(&_destroyrat)> lhsSmartRat(this->ToPRAT(), &_destroyrat);
|
shared_ptr<RAT> lhsSmartRat = this->ToSmartRAT();
|
||||||
auto lhsPrat = lhsSmartRat.get();
|
auto lhsPrat = lhsSmartRat.get();
|
||||||
unique_ptr<RAT, decltype(&_destroyrat)> rhsSmartRat(rhs.ToPRAT(), &_destroyrat);
|
shared_ptr<RAT> rhsSmartRat = rhs.ToSmartRAT();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
xorrat(&lhsPrat, rhsSmartRat.get(), RATIONAL_BASE, RATIONAL_PRECISION);
|
xorrat(&lhsPrat, rhsSmartRat.get(), RATIONAL_BASE, RATIONAL_PRECISION);
|
||||||
|
@ -346,8 +356,8 @@ namespace CalcEngine
|
||||||
|
|
||||||
bool operator==(Rational const& lhs, Rational const& rhs)
|
bool operator==(Rational const& lhs, Rational const& rhs)
|
||||||
{
|
{
|
||||||
unique_ptr<RAT, decltype(&_destroyrat)> lhsSmartRat(lhs.ToPRAT(), &_destroyrat);
|
shared_ptr<RAT> lhsSmartRat = lhs.ToSmartRAT();
|
||||||
unique_ptr<RAT, decltype(&_destroyrat)> rhsSmartRat(rhs.ToPRAT(), &_destroyrat);
|
shared_ptr<RAT> rhsSmartRat = rhs.ToSmartRAT();
|
||||||
|
|
||||||
bool result = false;
|
bool result = false;
|
||||||
try
|
try
|
||||||
|
@ -369,8 +379,8 @@ namespace CalcEngine
|
||||||
|
|
||||||
bool operator<(Rational const& lhs, Rational const& rhs)
|
bool operator<(Rational const& lhs, Rational const& rhs)
|
||||||
{
|
{
|
||||||
unique_ptr<RAT, decltype(&_destroyrat)> lhsSmartRat(lhs.ToPRAT(), &_destroyrat);
|
shared_ptr<RAT> lhsSmartRat = lhs.ToSmartRAT();
|
||||||
unique_ptr<RAT, decltype(&_destroyrat)> rhsSmartRat(rhs.ToPRAT(), &_destroyrat);
|
shared_ptr<RAT> rhsSmartRat = rhs.ToSmartRAT();
|
||||||
|
|
||||||
bool result = false;
|
bool result = false;
|
||||||
try
|
try
|
||||||
|
@ -402,7 +412,7 @@ namespace CalcEngine
|
||||||
|
|
||||||
wstring Rational::ToString(uint32_t radix, NUMOBJ_FMT fmt, int32_t precision) const
|
wstring Rational::ToString(uint32_t radix, NUMOBJ_FMT fmt, int32_t precision) const
|
||||||
{
|
{
|
||||||
unique_ptr<RAT, decltype(&_destroyrat)> SmartRat(this->ToPRAT(), &_destroyrat);
|
shared_ptr<RAT> SmartRat = this->ToSmartRAT();
|
||||||
auto PRAT = SmartRat.get();
|
auto PRAT = SmartRat.get();
|
||||||
wstring result{};
|
wstring result{};
|
||||||
|
|
||||||
|
@ -420,7 +430,7 @@ namespace CalcEngine
|
||||||
|
|
||||||
uint64_t Rational::ToUInt64_t() const
|
uint64_t Rational::ToUInt64_t() const
|
||||||
{
|
{
|
||||||
unique_ptr<RAT, decltype(&_destroyrat)> smartRat(this->ToPRAT(), &_destroyrat);
|
shared_ptr<RAT> smartRat = this->ToSmartRAT();
|
||||||
uint64_t result;
|
uint64_t result;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
|
@ -26,6 +26,7 @@ namespace CalcEngine
|
||||||
|
|
||||||
explicit Rational(PRAT prat) noexcept;
|
explicit Rational(PRAT prat) noexcept;
|
||||||
PRAT ToPRAT() const;
|
PRAT ToPRAT() const;
|
||||||
|
std::shared_ptr<RAT> ToSmartRAT() const;
|
||||||
|
|
||||||
Number const& P() const;
|
Number const& P() const;
|
||||||
Number const& Q() const;
|
Number const& Q() const;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue