The Propeller chip features a powerful set of math and logic operators. A subset of these operators is supported by the Propeller Assembly language; however, since the Spin language has a use for every form of operator supported by the Propeller, this section describes every operator in detail. Please see the Operators section for a list of operators available in Propeller Assembly.
...
Math and Logic Operators | |||||||
---|---|---|---|---|---|---|---|
Operator | Assignment Usage | Constant Expressions1 | Is Unary | Description | |||
Integer | Float | ||||||
= | always | n/a1 | n/a1 |
| Constant Assignment '=' (CON blocks only) | ||
:= | always | n/a1 | n/a1 |
| Variable Assignment ':=' (PUB/PRI blocks only) | ||
+ | += | ✓ | ✓ |
| |||
+ | never | ✓ | ✓ | ✓ | |||
- | -= | ✓ | ✓ |
| |||
- | if solo | ✓ | ✓ | ✓ | |||
always |
|
| ✓ | Decrement, pre- or post- '--' ((--X) or (X--)) | |||
++ | always |
|
| ✓ | Decrement, pre- or post- '++' ((++X) or (X++)) | ||
* | *= | ✓ | ✓ |
| Multiply, Return Low '*', '*=', multiply and return lower 32 bits (signed) | ||
** | **= | ✓ |
|
| Multiply, Return High '**', '**=', multiply and return upper 32 bits (signed) | ||
/ | /= | ✓ | ✓ |
| Divide '/', '/=' (signed) | ||
// | //= | ✓ |
|
| Modulus '//', '//=' (signed) | ||
#> | #>= | ✓ | ✓ |
| Limit Minimum '#>', '#>=' (signed) | ||
<# | <#= | ✓ | ✓ | Limit Maximum '<#', '<#=' (signed) | |||
^^ | if solo | ✓ | ✓ | ✓ | |||
| | | if solo | ✓ | ✓ | Absolute Value '| |' | |||
~ | always |
|
| ✓ | Sign-Extend 7 or Post-Clear '~', sign-extend from bit 7 (~X) or post-clear to 0 (X~); all bits low | ||
~~ | always |
|
| ✓ | Sign-Extend 15 or Post-Set '~~', sign-extend from bit 15 (~~X) or post-set to -1 (X~~); all bits high | ||
~> | ~>= | ✓ |
|
| |||
? | always |
|
| ✓ | Random '?', random number forward (?X) or reverse (X?) | ||
|< | if solo | ✓ | ✓ | Bitwise Decode '|<', decode value (0 - 31) into single-high-bit long | |||
>| | if solo | ✓ | ✓ | Bitwise Encode '>|', encode long into value (0 - 32) as high-bit priority | |||
<< | <<= | ✓ |
|
| |||
>> | >>= | ✓ |
|
| |||
<- | <-= | ✓ |
|
| |||
-> | ->= | ✓ |
|
| |||
>< | ><= | ✓ |
|
| |||
& | &= | ✓ |
|
| |||
| | |= | ✓ | ✓ | Bitwise OR '|', '|=' | |||
^ | ^= | ✓ |
| ||||
! | if solo | ✓ |
| ✓ | |||
AND | AND= | ✓ | ✓ |
| Boolean AND 'AND', 'AND=' (promotes non-0 to -1) | ||
OR | OR= | ✓ | ✓ |
| Boolean OR 'OR', 'OR=' (promotes non-0 to -1) | ||
NOT | if solo | ✓ | ✓ | ✓ | Boolean NOT 'NOT' (promotes non-0 to -1) | ||
== | === | ✓ | ✓ |
| |||
<> | <>= | ✓ | ✓ |
| |||
< | <= | ✓ | ✓ |
| Boolean Is Less Than '<', '<=' (signed) | ||
> | >= | ✓ | ✓ |
| Boolean Is Greater Than '>', '>=' (signed) | ||
=< | =<= | ✓ | ✓ |
| Boolean Is Equal or Less '=<', '=<=' (signed) | ||
=> | =>= | ✓ | ✓ |
| |||
@ | never | ✓ |
| ✓ | |||
@@ | never |
|
| ✓ |
1 Assignment forms of operators are not allowed in constant expressions.|
.
Operator Precedence Levels | |||
---|---|---|---|
Level | Notes | Operators | Operator Names |
Highest (0) | Unary | --, ++, ~, ~~, ?, @, @@ | Inc/Decrement, Clear, Set, Random, Symbol/Object Address |
1 | Unary | +, -, ^^, | | , |<, >|, ! | Positive, Negate, Square Root, Absolute, Decode, Encode, Bitwise NOT |
2 |
| ->, <-, >>, <<, ~>, >< | Rotate Right/Left, Shift Right/Left, Shift Arithmetic Right, Reverse |
3 |
| & | Bitwise AND |
4 | | , ^ | Bitwise OR, Bitwise XOR | |
5 |
| *, **, /, // | Multiply-Low, Multiply-High, Divide, Modulus |
6 |
| +, - | Add, Subtract |
7 |
| #>, <# | Limit Minimum/Maximum |
8 |
| <, >, <>, ==, =<, => | Boolean: Less/Greater Than, Not Equal, Equal, Equal or Less/Greater |
9 | Unary | NOT | Boolean NOT |
10 |
| AND | Boolean AND |
11 |
| OR | Boolean OR |
Lowest (12) |
| =, :=, all other assignments | Constant/Variable Assignment, assignment forms of Binary Operators |
...