mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-18 21:30:38 +01:00
[poincare] Do not add parenthesis to often in childNeedsParenthesis
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user