From c08d7a4733aa07cc04130bdb2baa05b42a5a52da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Fri, 26 Jul 2019 16:51:36 +0200 Subject: [PATCH] [poincare] Add Parentheses around conjugate expression to easen reading: conj(2+i)*2 --> (conj(2+i))*2 --- poincare/src/addition.cpp | 3 +++ poincare/src/multiplication.cpp | 3 +++ poincare/src/subtraction.cpp | 3 +++ 3 files changed, 9 insertions(+) diff --git a/poincare/src/addition.cpp b/poincare/src/addition.cpp index 1232c432f..f7cd99964 100644 --- a/poincare/src/addition.cpp +++ b/poincare/src/addition.cpp @@ -35,6 +35,9 @@ bool AdditionNode::childNeedsUserParentheses(const Expression & child) const { && child.node() != childAtIndex(0)) { return true; } + if (child.type() == Type::Conjugate) { + return childNeedsUserParentheses(child.childAtIndex(0)); + } return false; } diff --git a/poincare/src/multiplication.cpp b/poincare/src/multiplication.cpp index 2fd143fcd..8cf9a3226 100644 --- a/poincare/src/multiplication.cpp +++ b/poincare/src/multiplication.cpp @@ -75,6 +75,9 @@ bool MultiplicationNode::childNeedsUserParentheses(const Expression & child) con } return true; } + if (child.type() == Type::Conjugate) { + return childNeedsUserParentheses(child.childAtIndex(0)); + } Type types[] = {Type::Subtraction, Type::Addition}; return child.isOfType(types, 2); } diff --git a/poincare/src/subtraction.cpp b/poincare/src/subtraction.cpp index 1f09c2ec2..cee90b315 100644 --- a/poincare/src/subtraction.cpp +++ b/poincare/src/subtraction.cpp @@ -30,6 +30,9 @@ bool SubtractionNode::childNeedsUserParentheses(const Expression & child) const if (child.isNumber() && static_cast(child).sign() == Sign::Negative) { return true; } + if (child.type() == Type::Conjugate) { + return childNeedsUserParentheses(child.childAtIndex(0)); + } Type types[] = {Type::Subtraction, Type::Opposite, Type::Addition}; return child.isOfType(types, 3); }