From d35caae85456a763520b9540a8e65a4e94c329bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Thu, 5 Oct 2017 17:57:30 +0200 Subject: [PATCH] [poincare] Fix Multiplication::simplify Change-Id: I8c2b7a1f40a54c121c3068abb15e4a711d1aa115 --- poincare/src/multiplication.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/poincare/src/multiplication.cpp b/poincare/src/multiplication.cpp index 26bcbf32e..e5e78fa24 100644 --- a/poincare/src/multiplication.cpp +++ b/poincare/src/multiplication.cpp @@ -69,15 +69,20 @@ bool Multiplication::HaveSameNonRationalFactors(const Expression * e1, const Exp } void Multiplication::privateSimplify() { - for (int i=0; itype() == Type::Multiplication) { mergeOperands(static_cast(o)); + index = 0; } else if (o->type() == Type::Rational && static_cast(o)->isZero()) { replaceWith(new Rational(Integer(0)), true); + return; } /* if (o->type() == Type::Undefined) { * replaceWith(new Undefined(), true); + * return; * }*/ } sortChildren(); @@ -100,8 +105,6 @@ void Multiplication::factorizeChildren(Expression * e1, Expression * e2) { const Expression * addOperands[2] = {CreateExponent(e1), CreateExponent(e2)}; removeOperand(e2, true); Expression * s = new Addition(addOperands, 2, false); - s->setParent(this); - s->simplify(); removeOperand(e2, true); if (e1->type() == Type::Power) { e1->replaceOperand(e1->operand(1), s, true); @@ -109,6 +112,7 @@ void Multiplication::factorizeChildren(Expression * e1, Expression * e2) { const Expression * operands[2] = {e1, s}; e1->replaceWith(new Power(operands, false), false); } + s->privateSimplify(); } const Expression * Multiplication::CreateExponent(Expression * e) {