Exemple #1
0
 static bool ShouldWrap(Expr expr, OperationPriority priority, ExpressionOrder order)
 {
     Func<OperationPriority, bool> shouldWrap = x => priority >= x;
     return expr.MatchStrict(
         add: x => shouldWrap(OperationPriority.Add),
         mult: x => IsMinusExpression(x) || shouldWrap(OperationPriority.Multiply),
         div: (x, y) => shouldWrap(OperationPriority.Divide),
         power: (x, y) => true, //shouldWrap(OperationPriority.Power),
         sqrt: x => false,
         param: x => false,
         @const: x => {
             if(x.IsFraction())
                 return shouldWrap(OperationPriority.Power);
             if(order == ExpressionOrder.Head)
                 return false;
             return x < 0;
         }
     );
 }