-
Notifications
You must be signed in to change notification settings - Fork 0
Operator Precedence
Operator precedence refers to the order in which operators should be evaluated. Precedence is defined via a simple enum:
enum {
DDPrecedenceUnknown = -1,
DDPrecedenceNone = 0,
DDPrecedenceBitwiseOr,
DDPrecedenceBitwiseXor,
DDPrecedenceBitwiseAnd,
DDPrecedenceLeftShift,
DDPrecedenceRightShift,
DDPrecedenceModulo,
DDPrecedenceSubtraction,
DDPrecedenceAddition = DDPrecedenceSubtraction,
DDPrecedenceDivision,
DDPrecedenceMultiplication = DDPrecedenceDivision,
DDPrecedenceUnary,
DDPrecedenceFactorial,
DDPrecedencePower,
DDPrecedenceParentheses
};
Parentheses produce the highest precedence. Thus, expressions inside parentheses should be evaluated before anything else.
Factorial, despite being a unary operator, has its own precedence, since it does not follow the semantics of other unary operators. Most unary operators precede the number to which they're applied. Factorial is unique in that it follows the term it modifies.
Muliplication has the same precedence as division, since they are the same operation. (Division is simply multiplication by the inverse) Similarly, addition and subtraction have the same precedence.
This list was deduced by playing around with expressions on WolframAlpha.