diff --git a/poincare/src/power.cpp b/poincare/src/power.cpp index 4ab6fb07f..525e9a89f 100644 --- a/poincare/src/power.cpp +++ b/poincare/src/power.cpp @@ -439,6 +439,12 @@ Expression Power::shallowReduce(ExpressionNode::ReductionContext reductionContex if (exponent.isNegative()) { index.setSign(ExpressionNode::Sign::Positive, reductionContext); Expression reducedPositiveExponentMatrix = shallowReduce(reductionContext); + if (reducedPositiveExponentMatrix.type() == ExpressionNode::Type::Power) { + /* The shallowReduce did not work, stop here so we do not get in an + * infinite loop. */ + static_cast(reducedPositiveExponentMatrix).childAtIndex(1).setSign(ExpressionNode::Sign::Negative, reductionContext); + return reducedPositiveExponentMatrix; + } Expression dummyExpression = Undefined::Builder(); MatrixInverse inv = MatrixInverse::Builder(dummyExpression); reducedPositiveExponentMatrix.replaceWithInPlace(inv);