[poincare/unit] Fix crash with Units in Graph

In Graph, the weak ReductionTarget would cause _X^0 to not be simplified
to 1, and would break an assertion in
Unit::chooseBestRepresentativeAndPrefix.

Change-Id: I8167a472802baf0a73bf48513f492e78517107ef
This commit is contained in:
Gabriel Ozouf
2020-08-28 12:29:04 +02:00
committed by Émilie Feral
parent 9be5e7671c
commit 1917999f6d

View File

@@ -687,6 +687,13 @@ static void chooseBestRepresentativeAndPrefixForValueOnSingleUnit(Expression uni
factor = factor.childAtIndex(0);
}
assert(factor.type() == ExpressionNode::Type::Unit);
if (exponent == 0.f) {
/* Finding the best representative for a unit with exponent 0 doesn't
* really make sense, and should only happen with a weak ReductionTarget
* (such as in Graph app), that only rely on approximations. We keep the
* unit unchanged as it will approximate to undef anyway. */
return;
}
static_cast<Unit &>(factor).chooseBestRepresentativeAndPrefix(value, exponent, reductionContext, optimizePrefix);
}