diff --git a/src/fintamath/expressions/ExpressionUtils.cpp b/src/fintamath/expressions/ExpressionUtils.cpp index afb997e37..9e5078ed7 100644 --- a/src/fintamath/expressions/ExpressionUtils.cpp +++ b/src/fintamath/expressions/ExpressionUtils.cpp @@ -75,13 +75,16 @@ std::string operatorChildToString(const IOperator &oper, const ArgumentPtr &chil bool shouldPutInBrackets = false; if (childOper) { - shouldPutInBrackets = oper.getOperatorPriority() == IOperator::Priority::PostfixUnary || - childOper->getOperatorPriority() > oper.getOperatorPriority(); - - shouldPutInBrackets = shouldPutInBrackets || - (childOper->getFunctionType() == IFunction::Type::Unary - ? childOper->getOperatorPriority() == oper.getOperatorPriority() - : !oper.isAssociative()); + if (oper.getOperatorPriority() == IOperator::Priority::PostfixUnary) { + shouldPutInBrackets = true; + } + else if (childOper->getFunctionType() == IFunction::Type::Unary) { + shouldPutInBrackets = childOper->getOperatorPriority() >= oper.getOperatorPriority(); + } + else { + shouldPutInBrackets = childOper->getOperatorPriority() > oper.getOperatorPriority() || + !oper.isAssociative(); + } } return shouldPutInBrackets ? putInBrackets(childStr) : childStr; diff --git a/src/fintamath/expressions/binary/DivExpression.cpp b/src/fintamath/expressions/binary/DivExpression.cpp index cff018c8c..8a5439c5c 100644 --- a/src/fintamath/expressions/binary/DivExpression.cpp +++ b/src/fintamath/expressions/binary/DivExpression.cpp @@ -33,7 +33,7 @@ DivExpression::DivExpression(ArgumentPtr inLhsChild, ArgumentPtr inRhsChild) } std::string DivExpression::toString() const { - if (isNegated(lhsChild)) { + if (isNegated(lhsChild)) { // TODO: find more efficient solution ArgumentPtr innerDiv = divExpr(negExpr(lhsChild)->toMinimalObject(), rhsChild); return negExpr(innerDiv)->toString(); }