An operator executes a mathematical operation with two values. Examples are addition and multiplication.
SpeQ uses the following operators for calculations. |
| Operator | Description | Example |
|---|---|---|
| Plus, addition | 2 + 3 Ans = 5 |
|
| Minus, subtraction | 7.5 - 3 Ans = 4.5 |
|
| Multiplication | 8 * 2.5 Ans = 20 |
|
| Division | 5 / 4 Ans = 1.25 |
|
Mod |
Modulus, the remainder of an integer division |
7 % 3 Ans = 1 |
| Power | 2 ^ 3 Ans = 8 |
|
^2 |
Square | 4² Ans = 16 |
^3 |
Cube | 2³ Ans = 8 |
| Operator |
Description |
Example |
|---|---|---|
| Bitwise And | 11 & 6 Ans = 2 |
|
| Bitwise Or | 1 | 2 | 4 Ans = 7 |
|
| Bitwise Exclusive Or | 1 || 2 Ans = 3 |
|
| Bitshift left a << b = a * (2^b) |
16 << 2 Ans = 64 |
|
| Bitshift right a >> b = a / (2^b) |
16 >> 2 Ans = 4 |
| Operator |
Description |
Example |
|---|---|---|
| Is equal to | (5-4 = 1) Ans = 1 |
|
| Is not equal to | (5-4 <> 1) Ans = 0 |
|
| Is smaller than | (2 < 3) Ans = 1 |
|
| Is bigger than | (2 > 3) Ans = 0 |
|
| Is smaller than or equal to | (2 <= 3-1) Ans = 1 |
|
| Is bigger than or equal to | (2 >= 3) Ans = 0 |
| Operator |
Description |
Example |
|---|---|---|
| And Returns 1 if both statements are true. |
(4-5 = 1) And (2<>3) Ans = 1 |
|
| Or Returns 1 if one or both statements are true. |
(4-5 = 2) Or (2<>3) Ans = 1 |
|
| Exclusive Or Returns 1 only if one of the statements is true. |
(4-5 = 2) Xor (2<>3) Ans = 1 |
|
( ) ! ² ³ ^ /, *, % +, - =, <>, <, >, <=, >= And, Or, Xor, &, |, ||, >>, << |
'Examples of using operators
2 * 3
Ans = 6
3 / 4
Ans = 0.75
2.5 + 3
Ans = 5.5
2.5 - 3
Ans = -0.5
2 * 3 + 4
Ans = 10
3 ^ 2
Ans = 9
1.5 * 2 ^ 2
Ans = 6
2.13 + 3.99 + 1.25 - 0.50 + 2.00
Ans = 8.87
'Examples of using logical and conditional operators
'Create a few variables to experiment with
a = 3.5;
b = 8.0;
c = 5.7;
'Test conditions of the variables
(a < b)
Ans = 1
(a = b)
Ans = 0
(b >= a) And (b >= c)
Ans = 1
(c >= b) And (c >= a)
Ans = 0
(c >= b) Or (c >= a)
Ans = 1