diff --git a/src/CalcManager/CEngine/Rational.cpp b/src/CalcManager/CEngine/Rational.cpp index 214a1176..bf6e8b4c 100644 --- a/src/CalcManager/CEngine/Rational.cpp +++ b/src/CalcManager/CEngine/Rational.cpp @@ -71,6 +71,16 @@ namespace CalcEngine return ret; } + shared_ptr Rational::ToSmartRAT() const + { + shared_ptr smartRat(_createrat(), &_destroyrat); + + smartRat.get()->pp = this->P().ToPNUMBER(); + smartRat.get()->pq = this->Q().ToPNUMBER(); + + return smartRat; + } + Number const& Rational::P() const { return m_p; @@ -128,9 +138,9 @@ namespace CalcEngine Rational& Rational::operator*=(Rational const& rhs) { - unique_ptr lhsSmartRat(this->ToPRAT(), &_destroyrat); + shared_ptr lhsSmartRat = this->ToSmartRAT(); auto lhsPrat = lhsSmartRat.get(); - unique_ptr rhsSmartRat(rhs.ToPRAT(), &_destroyrat); + shared_ptr rhsSmartRat = rhs.ToSmartRAT(); try { @@ -148,9 +158,9 @@ namespace CalcEngine Rational& Rational::operator/=(Rational const& rhs) { - unique_ptr lhsSmartRat(this->ToPRAT(), &_destroyrat); + shared_ptr lhsSmartRat = this->ToSmartRAT(); auto lhsPrat = lhsSmartRat.get(); - unique_ptr rhsSmartRat(rhs.ToPRAT(), &_destroyrat); + shared_ptr rhsSmartRat = rhs.ToSmartRAT(); try { @@ -168,9 +178,9 @@ namespace CalcEngine Rational& Rational::operator%=(Rational const& rhs) { - unique_ptr lhsSmartRat(this->ToPRAT(), &_destroyrat); + shared_ptr lhsSmartRat = this->ToSmartRAT(); auto lhsPrat = lhsSmartRat.get(); - unique_ptr rhsSmartRat(rhs.ToPRAT(), &_destroyrat); + shared_ptr rhsSmartRat = rhs.ToSmartRAT(); try { @@ -188,9 +198,9 @@ namespace CalcEngine Rational& Rational::operator<<=(Rational const& rhs) { - unique_ptr lhsSmartRat(this->ToPRAT(), &_destroyrat); + shared_ptr lhsSmartRat = this->ToSmartRAT(); auto lhsPrat = lhsSmartRat.get(); - unique_ptr rhsSmartRat(rhs.ToPRAT(), &_destroyrat); + shared_ptr rhsSmartRat = rhs.ToSmartRAT(); try { @@ -208,9 +218,9 @@ namespace CalcEngine Rational& Rational::operator>>=(Rational const& rhs) { - unique_ptr lhsSmartRat(this->ToPRAT(), &_destroyrat); + shared_ptr lhsSmartRat = this->ToSmartRAT(); auto lhsPrat = lhsSmartRat.get(); - unique_ptr rhsSmartRat(rhs.ToPRAT(), &_destroyrat); + shared_ptr rhsSmartRat = rhs.ToSmartRAT(); try { @@ -228,9 +238,9 @@ namespace CalcEngine Rational& Rational::operator&=(Rational const& rhs) { - unique_ptr lhsSmartRat(this->ToPRAT(), &_destroyrat); + shared_ptr lhsSmartRat = this->ToSmartRAT(); auto lhsPrat = lhsSmartRat.get(); - unique_ptr rhsSmartRat(rhs.ToPRAT(), &_destroyrat); + shared_ptr rhsSmartRat = rhs.ToSmartRAT(); try { @@ -248,9 +258,9 @@ namespace CalcEngine Rational& Rational::operator|=(Rational const& rhs) { - unique_ptr lhsSmartRat(this->ToPRAT(), &_destroyrat); + shared_ptr lhsSmartRat = this->ToSmartRAT(); auto lhsPrat = lhsSmartRat.get(); - unique_ptr rhsSmartRat(rhs.ToPRAT(), &_destroyrat); + shared_ptr rhsSmartRat = rhs.ToSmartRAT(); try { orrat(&lhsPrat, rhsSmartRat.get(), RATIONAL_BASE, RATIONAL_PRECISION); @@ -267,9 +277,9 @@ namespace CalcEngine Rational& Rational::operator^=(Rational const& rhs) { - unique_ptr lhsSmartRat(this->ToPRAT(), &_destroyrat); + shared_ptr lhsSmartRat = this->ToSmartRAT(); auto lhsPrat = lhsSmartRat.get(); - unique_ptr rhsSmartRat(rhs.ToPRAT(), &_destroyrat); + shared_ptr rhsSmartRat = rhs.ToSmartRAT(); try { xorrat(&lhsPrat, rhsSmartRat.get(), RATIONAL_BASE, RATIONAL_PRECISION); @@ -346,8 +356,8 @@ namespace CalcEngine bool operator==(Rational const& lhs, Rational const& rhs) { - unique_ptr lhsSmartRat(lhs.ToPRAT(), &_destroyrat); - unique_ptr rhsSmartRat(rhs.ToPRAT(), &_destroyrat); + shared_ptr lhsSmartRat = lhs.ToSmartRAT(); + shared_ptr rhsSmartRat = rhs.ToSmartRAT(); bool result = false; try @@ -369,8 +379,8 @@ namespace CalcEngine bool operator<(Rational const& lhs, Rational const& rhs) { - unique_ptr lhsSmartRat(lhs.ToPRAT(), &_destroyrat); - unique_ptr rhsSmartRat(rhs.ToPRAT(), &_destroyrat); + shared_ptr lhsSmartRat = lhs.ToSmartRAT(); + shared_ptr rhsSmartRat = rhs.ToSmartRAT(); bool result = false; try @@ -402,7 +412,7 @@ namespace CalcEngine wstring Rational::ToString(uint32_t radix, NUMOBJ_FMT fmt, int32_t precision) const { - unique_ptr SmartRat(this->ToPRAT(), &_destroyrat); + shared_ptr SmartRat = this->ToSmartRAT(); auto PRAT = SmartRat.get(); wstring result{}; @@ -420,7 +430,7 @@ namespace CalcEngine uint64_t Rational::ToUInt64_t() const { - unique_ptr smartRat(this->ToPRAT(), &_destroyrat); + shared_ptr smartRat = this->ToSmartRAT(); uint64_t result; try { diff --git a/src/CalcManager/Header Files/Rational.h b/src/CalcManager/Header Files/Rational.h index 8ded3c27..e1d579a8 100644 --- a/src/CalcManager/Header Files/Rational.h +++ b/src/CalcManager/Header Files/Rational.h @@ -26,6 +26,7 @@ namespace CalcEngine explicit Rational(PRAT prat) noexcept; PRAT ToPRAT() const; + std::shared_ptr ToSmartRAT() const; Number const& P() const; Number const& Q() const;