Navigation bar
  Start Previous page
 31 of 172 
Next page End  

ZBasic Language Reference
24
ZX Microcontroller Family
BasicX Compatibility Note
In BasicX mode, a different operator precedence set is used, as shown in the
table below, in order to be compatible with BasicX.
Operator Precedence
Precedence Level
Operators
5 (highest)
^
4
+(unary) -(unary)
3
Not
2
* / \ Mod And
1
+ - Or Xor &
0 (lowest)
= < > <= >= <>
2.4.2 Operator Associativity
After studying the precedence table in the preceding section, the obvious question would be what
happens when two operators have the same precedence?
b = b - 5 + 3
In case of equal precedence, the operators are applied in the order dictated by the associativity of the
operator.  Except for the exponentiation operator, all operators in ZBasic are left associative.  This means
that given equal precedence operators they are applied in left to right order.  Exponentiation is right
associative meaning that they will be applied in right to left order.
However, no matter what the precedence levels are you can force the operators to be applied in any
order that you wish by utilizing parentheses.  Consider the two examples below.
b = (b – 5) + 3
b = b – (5 + 3)
The parentheses indicate that the expression within should be evaluated first after which the result may
be used as an operand in another operation.
2.4.3 Arithmetic Operators
The arithmetic operators are listed in the table below along with the permitted operand types.  The result
is the same type as the operands.
Arithmetic Operators
Function
Type
Operator
Permitted Operand Types
Negation
Unary
-
any numeric
Addition
Binary
+
any numeric
Subtraction
Binary
-
any numeric
Multiplication
Binary
*
any numeric¹
Division, Integer
Binary
\
any integral¹
Division, Real
Binary
/
Single
Modulus
Binary
Mod
any numeric¹
Exponentiation
Binary
^
any numeric²
Notes:
¹ In BasicX mode, operating on UnsignedLong is not supported.
² the result will be the same type as the left operand.  In BasicX mode, the left
operand must be Single and the right operand must be either Single or Integer.
Previous page Top Next page