 |
Operator Precedence
! | | Logical not
| - | | Negate
| ~ | | Bitwise not
| & | | Index
| * | | Multiply
| / | | Divide
| % | | Modulus
| + | | Add
| - | | Subtract
| << | | Bitwise shift-left
| >> | | Bitwise shift-right
| < | | Less than
| > | | Greater than
| <= | | Less than or equal to
| >= | | Greater than or equal to
| == | | Equal to
| != | | Not equal to
| & | | Bitwise and
| ^ | | Bitwise xor
| | | | Bitwise or
| && | | Logical and
| || | | Logical or
| ?: | | Conditional
| = | | Assignment
|
The operators highest in the above table have the highest precedence.
Use parenthesis to disambiguate and clarify. Since the operators
are taken directly from C, any beginning C manual can further
explain them.
Arithmetic
-expression // negate
expression + expression // add
expression - expression // subtract
expression * expression // multiply
expression / expression // divide
expression % expression // modulus
These are self-explanatory, except maybe modulo, which effectively
divides the first operand by the second and returns the remainder.
And now for a public service message: never modulo or
divide by zero. All division in integer division.
Logical
!expression // not
expression && expression // and
expression || expression // or
These operations return the logical value true or false. 'Not' returns
true only if the expression is false, 'and' returns true only if both
expressionessions are true, and 'or' returns true if either or both of the expressions
are true. Otherwise, they return false.
Comparative
expression == expression // equal to
expression != expression // not equal to
expression < expression // less than
expression > expression // greater than
expression <= expression // less than or equal to
expression >= expression // greater than or equal to
These compare expressions and return true or false.
Bitwise
~expression // one's-compliment
expression & expression // and
expression | expression // or
expression ^ expression // exclusive-or
These perform their boolean operation wise of every bit of the operand.
expression << expression // shift-left
expression >> expression // shift-right
'Shift-left' shifts left each bit in the first operand by the number given in the
second operand, effectively multiplying it by 2 for each shift. 'Shift-right' shifts
the other way, dividing the operand's value in half each time.
See Also...
Miscellaneous
expression ? expression : expression // conditional
This is an if-statement disguised as an expression. If the first expression
is true, the second expression is evaluated, otherwise the third is.
&identifier // index/address
This operator is used to take the index of a script or static variable,
rather than to call it.
|