User Manual
MCP Series
Brushed DC Motor Controllers
MCP Series User Manual
129
3.2.5 Operator Precedence
All math functions have a precedence order. This simply means each math function in an
expression is calculated based on its precedence not necessarily based on the order in which it
appears in the expression. This even holds true for math as it was taught in school. However, the
precedence of order may differ.
To solve the following equation 2+2*5/10 = 3 MCL would start with multiplication rst since it
has the higher precedence order. 2*5 will be calculated rst which equals 10, then divide 10
by 10 which equals 1, then addition of 2 which equals 3. The 2 was added last since it had the
lowest precedence.
The multiplication and division operators have equal precedence, and both have higher
precedence than addition and subtraction. Now you can change the order in which the math is
performed by using parenthesis. This will force a specic order. Using parentheses, the following
expression ((2+2)*5) /10 would yield a result of 2.
3.2.6 Precedence Table
Order Operation
1st NOT, ABS, SIN, COS, - (NEG), SQR, RANDOM, TOINT, TOFLOAT, BIN2BCD, ~(Binary NOT),
!(Binary NOT), NOT(Logical NOT), FABS, FSQRT, FSIN, FCOS, FTAN, FASIN, FACOS, FATAN,
FSINH, FCOSH, FTANH, FATANH, FLN, FEXP
2nd Dig
3rd MAX, MIN
4th *, **, */, /, //
5th +, -
6th <<, >>
7th <, <=, =, >=, >, <>
8th &, |, ^, &/, |/, ^/
9th And, Or, Xor
- (Negative)
Signs an expression (integer or oating point) as a negative value.
Temp var Byte
Result var Byte
Temp = 1
Result = Temp + -1
Temp is rst is set to equal 1. Then -1 is added. -1 is a signed integer. So Result now equals 0.
Since 1 added to -1 equals 0.