From 0c040a7db6f0fa35f4127f019e3cfc8eec0b59b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9a=20Saviot?= Date: Wed, 3 Jun 2020 11:39:37 +0200 Subject: [PATCH] [poincare/power] Fix infinite loop in reduction Fix the broken simplification test 1/identity(2)^500 --- poincare/src/power.cpp | 6 ++++++ 1 file changed, 6 insertions(+) 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);