Remove unnecessary Rational::IsZero() in favor of == 0 comparisons

This commit is contained in:
Josh Koon 2019-02-25 10:22:13 -08:00
commit 14d8dc964f
4 changed files with 4 additions and 13 deletions

View file

@ -444,11 +444,6 @@ namespace CalcEngine
return !(lhs < rhs); return !(lhs < rhs);
} }
bool Rational::IsZero() const
{
return this->P().IsZero();
}
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
{ {
PRAT rat = this->ToPRAT(); PRAT rat = this->ToPRAT();

View file

@ -11,7 +11,7 @@ using namespace CalcEngine::RationalMath;
CalcEngine::Rational CCalcEngine::DoOperation(int operation, CalcEngine::Rational const& lhs, CalcEngine::Rational const& rhs) CalcEngine::Rational CCalcEngine::DoOperation(int operation, CalcEngine::Rational const& lhs, CalcEngine::Rational const& rhs)
{ {
// Remove any variance in how 0 could be represented in rat e.g. -0, 0/n, etc. // Remove any variance in how 0 could be represented in rat e.g. -0, 0/n, etc.
auto result = (!lhs.IsZero() ? lhs : 0); auto result = (lhs != 0 ? lhs : 0);
try try
{ {

View file

@ -85,12 +85,9 @@ bool CCalcEngine::TryToggleBit(CalcEngine::Rational& rat, DWORD wbitno)
} }
Rational result = Integer(rat); Rational result = Integer(rat);
if (result.IsZero())
{ // Remove any variance in how 0 could be represented in rat e.g. -0, 0/n, etc.
// This is the same work around happenning in SciCalcFunctions. Ought to move to intrat function itself. result = (result != 0 ? result : 0);
// Basic bug is there which doesn't treat 0/ n as 0, or -0 as 0 etc.
result = 0;
}
// XOR the result with 2^wbitno power // XOR the result with 2^wbitno power
rat = result ^ Pow(2, static_cast<int32_t>(wbitno)); rat = result ^ Pow(2, static_cast<int32_t>(wbitno));

View file

@ -63,7 +63,6 @@ namespace CalcEngine
friend bool operator<=(Rational const& lhs, Rational const& rhs); friend bool operator<=(Rational const& lhs, Rational const& rhs);
friend bool operator>=(Rational const& lhs, Rational const& rhs); friend bool operator>=(Rational const& lhs, Rational const& rhs);
bool IsZero() const;
std::wstring ToString(uint32_t radix, NUMOBJ_FMT format, int32_t precision) const; std::wstring ToString(uint32_t radix, NUMOBJ_FMT format, int32_t precision) const;
uint64_t ToUInt64_t() const; uint64_t ToUInt64_t() const;