RelExpression === RelExpression
RelExpression !== RelExpression
The === compares for identity, and !== compares for not identity. The type of the result is bool. The operands go through the usual conversions to bring them to a common type before comparison.
For operand types other than class objects, static or dynamic arrays, identity is defined as being the same as equality.
For class objects, identity is defined as the object references are for the same object.
For static and dynamic arrays, identity is defined as referring to the same array elements.
Relational Expressions
ShiftExpression < ShiftExpression
ShiftExpression <= ShiftExpression
ShiftExpression > ShiftExpression
ShiftExpression >= ShiftExpression
ShiftExpression !<>= ShiftExpression
ShiftExpression !<> ShiftExpression
ShiftExpression <> ShiftExpression
ShiftExpression <>= ShiftExpression
ShiftExpression !> ShiftExpression
ShiftExpression !>= ShiftExpression
ShiftExpression !< ShiftExpression
ShiftExpression !<= ShiftExpression
ShiftExpression in ShiftExpression
First, the integral promotions are done on the operands. The result type of a relational expression is bool.
For class objects, the result of Object.cmp() forms the left operand, and 0 forms the right operand. The result of the relational expression (o1 op o2) is:
(o1.cmp(o2) op 0)
It is an error to compare objects if one is null.
For static and dynamic arrays, the result of the relational op is the result of the operator applied to the first non-equal element of the array. If two arrays compare equal, but are of different lengths, the shorter array compares as "less" than the longer array.
Integer comparisons happen when both operands are integral types.
Integer comparison operators
|
Operator
|
Relation
|
<
|
less
|
>
|
greater
|
<=
|
less or equal
|
>=
|
greater or equal
|
==
|
equal
|
!=
|
not equal
|
It is an error to have one operand be signed and the other unsigned for a <, <=, > or >= expression. Use casts to make both operands signed or both operands unsigned.
Floating point comparisons
If one or both operands are floating point, then a floating point comparison is performed.
Useful floating point operations must take into account NAN values. In particular, a relational operator can have NAN operands. The result of a relational operation on float values is less, greater, equal, or unordered (unordered means either or both of the operands is a NAN). That means there are 14 possible comparison conditions to test for:
Floating point comparison operators
|
Operator
|
Greater Than
|
Less Than
|
Equal
|
Unordered
|
Exception
|
Relation
|
==
|
F
|
F
|
T
|
F
|
no
|
equal
|
!=
|
T
|
T
|
F
|
T
|
no
|
unordered, less, or greater
|
>
|
T
|
F
|
F
|
F
|
yes
|
greater
|
>=
|
T
|
F
|
T
|
F
|
yes
|
greater or equal
|
<
|
F
|
T
|
F
|
F
|
yes
|
less
|
<=
|
F
|
T
|
T
|
F
|
yes
|
less or equal
|
!<>=
|
F
|
F
|
F
|
T
|
no
|
unordered
|
<>
|
T
|
T
|
F
|
F
|
yes
|
less or greater
|
<>=
|
T
|
T
|
T
|
F
|
yes
|
less, equal, or greater
|
!<=
|
T
|
F
|
F
|
T
|
no
|
unordered or greater
|
!<
|
T
|
F
|
T
|
T
|
no
|
unordered, greater, or equal
|
!>=
|
F
|
T
|
F
|
T
|
no
|
unordered or less
|
!>
|
F
|
T
|
T
|
T
|
no
|
unordered, less, or equal
|
!<>
|
F
|
F
|
T
|
T
|
no
|
unordered or equal
| Notes: -
For floating point comparison operators, (a !op b) is not the same as !(a op b).
-
"Unordered" means one or both of the operands is a NAN.
-
"Exception" means the Invalid Exception is raised if one of the operands is a NAN.
In Expressions
ShiftExpression in ShiftExpression
An associative array can be tested to see if an element is in the array:
int foo[char[]];
.
if ("hello" in foo)
.
The in expression has the same precedence as the relational expressions <, <=, etc.
Share with your friends: |