Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
v3:expressions [2022/02/12 10:45] – neils | v3:expressions [2024/07/30 22:51] (current) – neils | ||
---|---|---|---|
Line 2: | Line 2: | ||
When no parentheses are present, arithmetic expressions are evaluated from left to right, with multiplication and division having a higher priority than addition and subtraction. | When no parentheses are present, arithmetic expressions are evaluated from left to right, with multiplication and division having a higher priority than addition and subtraction. | ||
+ | |||
+ | The following table explains operator precedence in XC=BASIC: | ||
| Highest | | Highest | ||
Line 9: | Line 11: | ||
| Lowest | | Lowest | ||
- | The arithmetic operators, '' | + | The arithmetic operators, '' |
PRINT 5/2 ' Outputs 2 | PRINT 5/2 ' Outputs 2 | ||
Line 16: | Line 18: | ||
Operators, except unary operators, accept two operands. These two operands do not have to be of the same type. In a mixed expression, the operands are promoted to the higher type, being BYTE the lowest and FLOAT the highest type. The table below summarizes the results of a partially evaluated expression. | Operators, except unary operators, accept two operands. These two operands do not have to be of the same type. In a mixed expression, the operands are promoted to the higher type, being BYTE the lowest and FLOAT the highest type. The table below summarizes the results of a partially evaluated expression. | ||
- | | ^ BYTE ^ WORD ^ INT ^ FLOAT ^ | + | ^ ^ BYTE ^ WORD ^ INT ^ LONG ^ FLOAT ^ DECIMAL |
- | ^ BYTE | BYTE | WORD | INT | FLOAT | | + | ^ BYTE | BYTE | WORD | INT | LONG | FLOAT | - |
- | ^ WORD | WORD | WORD | INT | FLOAT | | + | ^ WORD | WORD | WORD | INT | LONG | FLOAT | - |
- | ^ INT | INT | INT | INT | FLOAT | | + | ^ INT | INT | INT | INT | LONG | FLOAT | - | |
- | ^ FLOAT | FLOAT | FLOAT | FLOAT | FLOAT | | + | ^ LONG | LONG | LONG | LONG | LONG | FLOAT | - |
+ | ^ FLOAT | FLOAT | FLOAT | FLOAT | FLOAT | FLOAT | - | | ||
+ | ^ DECIMAL | - | - | - | - | - | DECIMAL | | ||
+ | |||
+ | <adm note> | ||
+ | DECIMAL types can not be used together with other types. | ||
+ | </ | ||
- | The type of the data being operated on must be considered. For example, adding two values of type BYTE will always result in a value which is also of type BYTE, even if the result is too large to fit in a BYTE. For example, if '' | + | The type of the data being operated on must be considered. For example, adding two values of type BYTE will always result in a value which is also of type BYTE, even if the result is too large to fit in a BYTE. For example, if '' |
- | Likewise, adding two numeric literals | + | Likewise, adding |
DIM a AS INT | DIM a AS INT |