GOOC - Game Oriented Object C
GOOC - Game Oriented Object C
7.3. Comparison Operators
7.3. Comparison Operators
You use the comparison operators to determine how two operands relate to each other: are they equal to each other, is one larger than the other, is one smaller than the other, and so on. When you use any of the comparison operators, the result is either 1 or 0.
The equal-to operator == tests its two operands for equality. The result is 1 if the operands are equal, and 0 if the operands are not equal.
The not-equal-to operator != tests its two operands for equality. It is syntactic sugar for the expression !(foo == bar). The result is the opposite of the equal-to operator, that is, 1 if the operands are not equal, and 0 if they are.
Comparing decimal values for exact equality or inequality can produce unexpected results, due to limited precision.
Beyond equality and inequality, there are operators you can use to test if one value is less than, greater than, less-than-or-equal-to, or greater-than-or-equal-to another value:
- < results in 1 if its left operand is less than its right operand, and 0 otherwise.
- > results in 1 if its left operand is greater than its right operand, and 0 otherwise.
- <= results in 1 if its left operand is less than OR equal to its right operand, and 0 otherwise.
- >= results in 1 if its left operand is greater than OR equal to its right operand, and 0 otherwise.
Lastly, there is one comparison operator specifically for use with operands that store flags, where each bit corresponds to a flag. The bitwise-test operator \ (backwards slash, not to be confused with division) is unique to GOOC. The result is 1 if all of the bits that are enabled (set to 1) in the right operand are also enabled in the left operand, and 0 otherwise. This is used to verify if a number of flags (or bits) are enabled.