The precedence of an operator is a number that indicates the order in which operators are applied.
For example, in 1 + 2 * 3, the * operator has a higher precedence than the + operator, so it is applied first.
1 + 2 * 3
*
+
The precedence range from 0 to 1000. The larger the number, the higher the precedence, the more "binding" the operator is.
Here are some rough ranges for the precedence:
\lnot
POSTFIX_PRECEDENCE
!
'
EXPONENTIATION_PRECEDENCE
^
DIVISION_PRECEDENCE
\div
\land
\lor
\times
MULTIPLICATION_PRECEDENCE
ADDITION_PRECEDENCE
-
ARROW_PRECEDENCE
\to
\rightarrow
ASSIGNMENT_PRECEDENCE
:=
COMPARISON_PRECEDENCE
\lt
\gt
\leq
,
;
Some constants are defined below for common precedence values.
Note: MathML defines some operator precedence, but it has some issues and inconsistencies. However, whenever possible we adopted the MathML precedence. See https://www.w3.org/TR/2009/WD-MathML3-20090924/appendixc.html
For reference, the JavaScript operator precedence is documented here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_precedence
THEORY OF OPERATIONS
The precedence of an operator is a number that indicates the order in which operators are applied.
For example, in
1 + 2 * 3
, the*
operator has a higher precedence than the+
operator, so it is applied first.The precedence range from 0 to 1000. The larger the number, the higher the precedence, the more "binding" the operator is.
Here are some rough ranges for the precedence:
\lnot
etc...POSTFIX_PRECEDENCE
= 810:!
,'
EXPONENTIATION_PRECEDENCE
= 700:^
DIVISION_PRECEDENCE
= 600:\div
\land
,\lor
,\times
, etc...MULTIPLICATION_PRECEDENCE
= 390:\times
ADDITION_PRECEDENCE
= 275:+
-
ARROW_PRECEDENCE
= 270:\to
\rightarrow
ASSIGNMENT_PRECEDENCE
= 260::=
COMPARISON_PRECEDENCE
= 245:\lt
\gt
\leq
,
,;
, etc...Some constants are defined below for common precedence values.
Note: MathML defines some operator precedence, but it has some issues and inconsistencies. However, whenever possible we adopted the MathML precedence. See https://www.w3.org/TR/2009/WD-MathML3-20090924/appendixc.html
For reference, the JavaScript operator precedence is documented here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_precedence