Arithmetic operators
- Operator
- Meaning
- +
- Add
- -
- Minus
- *
- Multiply
- /
- Divide
- %
- Integer divide (divide and return the integer part of the result)
- //
- Remainder (divide and return the remainder--not modulo, because the result might be negative)
- **
- Power® (raise a number to a whole-number power)
- Prefix -
- Same as the subtraction:
0 - number
- Prefix +
- Same as the addition:
0 + number
- #6
- Contains a numeric value representing an employee's annual salary.
- #15
- Contains a numeric value representing his annual travel allowance.
- #23
- Contains a numeric value representing his annual bonus.
(#6 + #15 + #23) > 100000
- #45
- Contains the number of sick days an employee is entitled to annually.
- #46
- Contains the number of sick days an employee has used in the current year.
(#46 / #45) >= .5
Note that in each of these examples, the arithmetic subexpression is contained in parentheses. This ensures that the entire subexpression is evaluated before the comparison operation.
- Operator
- Meaning
- + - ¬ \
- Prefix operators
- **
- Power®
- * /
- Multiply and divide
- + -
- Add and subtract
For example, * (multiply) has a higher priority than + (add), therefore 3+2*5
evaluates
as 13
(rather than the 25
that would
result if strict left to right evaluation occurred). To force the
addition to occur before the multiplication, rewrite the expression
as (3+2)*5.
Adding the parentheses makes the first
three tokens a subexpression.