From 2ea39fcaa4a66a069246ea7a6ed0fbb2aa1825ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Thu, 27 Dec 2018 15:09:20 +0100 Subject: [PATCH] [poincare] Addition: shallowBeautify sorts its children in decreasing order: 1+x+x^2 --> x^2+x+1 --- poincare/src/addition.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/poincare/src/addition.cpp b/poincare/src/addition.cpp index 279c6c9a4..26c48a371 100644 --- a/poincare/src/addition.cpp +++ b/poincare/src/addition.cpp @@ -99,6 +99,11 @@ Expression Addition::shallowBeautify(Context & context, Preferences::ComplexForm * Last but not least, special care must be taken when iterating over children * since we may remove some during the process. */ + /* Sort children in decreasing order: + * 1+x+x^2 --> x^2+x+1 + * 1+R(2) --> R(2)+1 */ + sortChildrenInPlace([](const ExpressionNode * e1, const ExpressionNode * e2, bool canBeInterrupted) { return ExpressionNode::SimplificationOrder(e2, e1, canBeInterrupted); }, true); + for (int i = 0; i < numberOfChildren(); i++) { // Try to make the child i positive if any negative numeral factor is found Expression subtractant = childAtIndex(i).makePositiveAnyNegativeNumeralFactor(context, complexFormat, angleUnit, ExpressionNode::ReductionTarget::User);