diff --git a/app/common/rational.cpp b/app/common/rational.cpp index 36952ca114..5be6f04f35 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 0244e989a7..59ed8775ee 100644 --- a/app/common/rational.h +++ b/app/common/rational.h @@ -37,18 +37,7 @@ class rational 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 @@ class rational intType numer; intType denom; + void validateConstructor(); + //Function: ensures denom >= 0 void fixSigns(); //Function: ensures lowest form