5.6.9.8 Logical Operators
Logical operators are simple data operators that perform bitwise computations on their operands.
-
logical-operator-expression = not-operator-expression / and-operator-expression / or-operator-expression / xor-operator-expression / imp-operator-expression / eqv-operator-expression
Static semantics:
§ Logical operators are statically resolved as simple data operators.
§ A logical operator is invalid if the declared type of any operand is an array or a UDT.
§ For unary logical operators, the operator has the following declared type, based on the declared type of its operand:
Operand Declared Type |
Operator Declared Type |
---|---|
Byte |
Byte |
Boolean |
Boolean |
Integer |
Integer |
Any floating-point or fixed-point numeric type, Long, String, String * length or Date |
Long |
LongLong |
LongLong |
Variant |
Variant |
§ For binary logical operators, the operator has the following declared type, based on the declared type of its operands:
Left Operand Declared Type |
Right Operand Declared Type |
Operator Declared Type |
---|---|---|
Byte |
Byte |
Byte |
Boolean |
Boolean |
Boolean |
Byte or Integer |
Boolean or Integer |
Integer |
Boolean or Integer |
Byte or Integer |
Integer |
Any floating-point or fixed-point numeric type, Long, String, String * length or Date |
Any numeric type except LongLong, String, String * length or Date |
Long |
Any numeric type except LongLong, String, String * length or Date |
Any floating-point or fixed-point numeric type, Long, String, String * length or Date |
Long |
LongLong |
Any numeric type, String, String * length or Date |
LongLong |
Any numeric type, String, String * length or Date |
LongLong |
LongLong |
Any type except an array or UDT |
Variant |
Variant |
Runtime semantics:
§ Logical operators are first evaluated as simple data operators.
§ If the value type of any operand is an array, UDT or Error, runtime error 13 (Type mismatch) is raised.
§ Before evaluating the logical operator, its non-Null operands undergo Let-coercion to the operator’s effective value type.
§ For unary logical operators, the effective value type is determined as follows, based on the value type of the operand:
Operand Value Type |
Effective Value Type |
---|---|
Byte |
Byte |
Boolean or Integer or Empty |
Integer |
Long |
Long |
LongLong |
LongLong |
Single |
Single |
Double or String |
Double |
Currency |
Currency |
Date |
Date (however, the operand is Let-coerced to Double instead) |
Decimal |
Decimal |
Null |
Null |
§ For binary logical operators, if either operator is null, the effective value type is determined as follows, based on the value types of the operands:
Left Operand Value Type |
Right Operand Value Type |
Effective Value Type |
---|---|---|
Byte or Null |
Byte |
Byte |
Byte |
Byte or Null |
Byte |
Boolean or Null |
Boolean |
Boolean (however, the operands are Let-coerced to Integer instead) |
Boolean |
Boolean or Null |
Boolean (however, the operands are Let-coerced to Integer instead) |
Byte, Boolean, Integer, Null or Empty |
Integer or Empty |
Integer |
Integer or Empty |
Byte, Boolean, Integer, Null or Empty |
Integer |
Byte |
Boolean |
Integer |
Boolean |
Byte |
Integer |
Any floating-point or fixed-point numeric type, Long, String, Date or Empty |
Any numeric type except LongLong, String, Date, Null or Empty |
Long |
Any numeric type except LongLong, String, Date, Null or Empty |
Any floating-point or fixed-point numeric type, Long, String, Date or Empty |
Long |
LongLong |
Any numeric type, String, Date or Empty |
LongLong |
Any numeric type, String, Date or Empty |
LongLong |
LongLong |
Null |
Null |
Null |
The value type of a logical operator is determined from the value the operator produces:
If the logical operator produces a value other than Null, the operator’s value type is its effective value type. The operator’s result value is Let-coerced to this value type.
Otherwise, if the logical operator produces Null, the operator’s value is Null.