Arithmetic operators perform normal mathematical operations. Several of these operators merit a word of explanation. The backslash (\) represents integral division. Integral division rounds its operands to an integral value, to produce a truncated quotient with no remainder. For example, 5 \ 2 evaluates to 2, and 9 \ 10 evaluates to 0. Integral division is also faster than floating-point division when using integral-class variables or expressions.
The remainder of an integral division can be determined with the MOD (modulo) operator (MOD is valid for all numeric types). MOD is similar to integral division except that it returns the remainder of the division rather than the quotient. For example, 5 MOD 2 returns the value 1, and 9 MOD 10 returns the value 9.
The ISTRUE operator returns TRUE only if its operand is TRUE (non-zero). ISTRUE is guaranteed to return -1 as its TRUE value, whereas the operators can return any non-zero value.
The ISFALSE operator returns TRUE only if its operand is FALSE (zero). ISFALSE is guaranteed to return -1 as its TRUE value, where the operators can return any non-zero value.
PowerBASIC arithmetic operators
Operator |
Action |
Example |
^ |
Exponentiation |
10^4 |
- |
Negation |
-16 |
* |
Multiplication |
45 * 19 |
/ |
Floating-point division |
45 / 19 |
\ |
Integral division |
45 \ 19 |
MOD |
Modulo |
45 MOD 19 |
+ |
Add |
45 + 19 |
- |
Subtract |
45 - 19 |
ISFALSE |
Boolean False |
ISFALSE 45 |
ISTRUE |
Boolean True |
ISTRUE 19 |
Bit manipulation operations |
NOT 0, 45 AND 19 45 OR 19, 45 XOR 19 45 EQV 19, 45 IMP 19 |
Note: PowerBASIC does not trap numeric overflow or underflow errors in equation and expression evaluation. Please refer to the chapter Errors and Error Trapping for more information.
It is recommended that this table be read in conjunction with the Mathematical Order of Operator Precedence table, and the effects that operator precedence has on the evaluation of numeric expressions.
See Also