From cd06b2f4acb14f20a63902ba933162c993105af6 Mon Sep 17 00:00:00 2001 From: itsmattkc Date: Mon, 20 Jan 2020 04:05:48 +1100 Subject: [PATCH] rational: validate values when constructed with AVRational `rational` is supposed to "fix signs" and "reduce" whenever its values are set, but I neglected to do this when its values were set by an AVRational. Now it will do so on both. --- app/common/rational.cpp | 17 +++++++++++++++++ app/common/rational.h | 15 +++------------ 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/app/common/rational.cpp b/app/common/rational.cpp index 36952ca11..5be6f04f3 100644 --- a/app/common/rational.cpp +++ b/app/common/rational.cpp @@ -7,6 +7,7 @@ rational::rational(const AVRational &r) : numer(r.num), denom(r.den) { + validateConstructor(); } rational rational::fromDouble(const double &flt) @@ -136,6 +137,22 @@ QString rational::toString() const return QStringLiteral("%1/%2").arg(QString::number(numer), QString::number(denom)); } +void rational::validateConstructor() +{ + if(denom != intType(0)) + { + if(numer != intType(0)) + { + fixSigns(); + reduce(); + } + else + denom = intType(0); + } + else + numer = intType(0); +} + //Assignment Operators const rational& rational::operator=(const rational &rhs) diff --git a/app/common/rational.h b/app/common/rational.h index 0244e989a..59ed8775e 100644 --- a/app/common/rational.h +++ b/app/common/rational.h @@ -37,18 +37,7 @@ public: rational(const intType &numerator, const intType &denominator) :numer(numerator), denom(denominator) { - if(denom != intType(0)) - { - if(numer != intType(0)) - { - fixSigns(); - reduce(); - } - else - denom = intType(0); - } - else - numer = intType(0); + validateConstructor(); } rational(const rational &rhs) = default; @@ -117,6 +106,8 @@ private: intType numer; intType denom; + void validateConstructor(); + //Function: ensures denom >= 0 void fixSigns(); //Function: ensures lowest form