Relational operations
As we know already one of the standards types of variables in MetaQuotes Language 4 is the type bool. A variable of the bool type can hold only two values: True and False. The value False is represented in the form of zero value, and the value True is equivalent to nonzero value.
The value of a relational operation or logic operation will have the bool type.
Relational operations
| Operation | Result |
| a == b | True if a equals b False if a doesn’t equal b |
| a != b | True if a doesn’t equal b False if a equals b |
| a < b | True if a is less than b False if a is greater or equal to b |
| a <= b | True if a is less or equal to b False if a is greater than b |
| a > b | True if a is greater than b False if a is less or equal to b |
| a >= b | True if a is greater or equal to b False if a is less than b |
Note: as floating-point numbers (the double type) can’t be represented exactly due to the limited number of significant digits after the point (in MetaQuotes Language 4 accuracy is 15 significant digits), it is impossible to compare them for equality (==) or iequality (!=) without prenormalization (I will speak about normalization of real numbers in following articles).
Logical operations
Let me remind you that nonzero values signify TRUE and zero values signify FALSE.
In this article I will consider such logical operations as NOT (!), OR (||) and AND (&&).
Logical negation NOT (!)
| Operand A | Value of the expression! A |
| TRUE | FALSE |
| FALSE | TRUE |
Example:
bool b;
b = false; // variable b equals false (FALSE)
b = !b; // variable b equals true (TRUE)
b = !b; // variable b equals false (FALSE)
Logical operation OR (||)
The result of a logical operation OR equals to true, if at least one of the operands equals true. If both operands are equal to false, then the result of logical OR will be also equal to false.
| Operand A | Operand B | Value of the expression A || B |
| FALSE | FALSE | FALSE |
| FALSE | TRUE | TRUE |
| TRUE | FALSE | TRUE |
| TRUE | TRUE | TRUE |
Example:
bool a = true; // a equals true
bool b = false; // b equals false
b = b || a; // b equals true
Logical operation AND (&&)
The result of logical operation AND will be equal to true only in the case when both operands are equal to true. In all other cases the result of the operation will be equal to false.
| Operand A | Operand B | Value of the expression A && B |
| FALSE (false) | FALSE (false) | FALSE (false) |
| FALSE (false) | TRUE (true) | FALSE (false) |
| TRUE (true) | FALSE (false) | FALSE (false) |
| TRUE (true) | TRUE (true) | TRUE (true) |
Example:
bool a = true; // a equals true
bool b = false; // b equals false
b = b && a; // b equals false
Next article: "
Bitwise operators"