[poincare] Do not add parenthesis to often in childNeedsParenthesis

This commit is contained in:
Léa Saviot
2018-11-21 11:16:42 +01:00
committed by Émilie Feral
parent d59c836abd
commit 9c788d31d4
3 changed files with 10 additions and 3 deletions

View File

@@ -31,7 +31,11 @@ int AdditionNode::getPolynomialCoefficients(Context & context, const char * symb
// Layout
bool AdditionNode::childNeedsParenthesis(const TreeNode * child) const {
if ((static_cast<const ExpressionNode *>(child)->isNumber() && static_cast<const ExpressionNode *>(child)->sign() == Sign::Negative) || static_cast<const ExpressionNode *>(child)->type() == Type::Opposite) {
if (((static_cast<const ExpressionNode *>(child)->isNumber()
&& static_cast<const ExpressionNode *>(child)->sign() == Sign::Negative)
|| static_cast<const ExpressionNode *>(child)->type() == Type::Opposite)
&& child != childAtIndex(0))
{
return true;
}
return false;

View File

@@ -21,8 +21,8 @@ bool FactorialNode::childNeedsParenthesis(const TreeNode * child) const {
if (static_cast<const ExpressionNode *>(child)->type() == Type::Rational && !static_cast<const RationalNode *>(child)->denominator().isOne()) {
return true;
}
Type types[] = {Type::Subtraction, Type::Opposite, Type::Multiplication, Type::Division, Type::Addition, Type::Power, Type::Factorial};
return static_cast<const ExpressionNode *>(child)->isOfType(types, 7);
Type types[] = {Type::Subtraction, Type::Opposite, Type::Multiplication, Type::Division, Type::Addition, Type::Power};
return static_cast<const ExpressionNode *>(child)->isOfType(types, 6);
}
// Simplification

View File

@@ -24,6 +24,9 @@ int SubtractionNode::polynomialDegree(Context & context, const char * symbolName
// Private
bool SubtractionNode::childNeedsParenthesis(const TreeNode * child) const {
if (child == childAtIndex(0)) {
return false;
}
if (static_cast<const ExpressionNode *>(child)->isNumber() && static_cast<const ExpressionNode *>(child)->sign() == Sign::Negative) {
return true;
}