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.
This commit is contained in:
itsmattkc
2020-01-20 04:07:09 +11:00
parent 649ee04eef
commit cd06b2f4ac
2 changed files with 20 additions and 12 deletions
+17
View File
@@ -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)