rix
rix copied to clipboard
Precedence rules: BEDMAS and order of operation
Parentheses are observed but otherwise order of operations is right to left. Therefor:
a = 3+3*3+3
b = (3+3)*3+3
result in:
a == 21
b == 36
Expected result:
a = 15
b = 21
a side effect is that the following code doesn't work:
print "cube root 27 = " + 27.0^^(1/3.0)
The above code attempts to raise a String to the power of 1/3. It can be fixed with parentheses as follows:
print "cube root 27 = " + (27.0^^(1/3.0))
can be easily fixed by splitting the MATHOP token into precedence groups, and defining precedence. e.g.
-
+,- -
*,/ -
^^