5.6.9.5 Relational Operators

Relational operators are simple data operators that perform comparisons between their operands.

 relational-operator-expression = equality-operator-expression / inequality-operator-expression / less-than-operator-expression / greater-than-operator-expression / less-than-equal-operator-expression / greater-than-equal-operator-expression

Static semantics:

§ Relational operators are statically resolved as simple data operators.

§ A relational operator is invalid if the declared type of any operand is an array or UDT.

§ A relational 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

Any type except an array, UDT or Variant

Any type except an array, UDT or Variant

Boolean

Any type except an array or UDT

Variant

Variant

Variant

Any type except an array or UDT

Variant

 

Runtime semantics:

§ Relational operators are first evaluated as simple data operators.

§ If the value type of any operand is an array or UDT, runtime error 13 (Type mismatch) is raised.

§ Before evaluating the relational operator, its non-Null operands undergo Let-coercion to the operator’s effective value type.

§ 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

Byte, String or Empty

Byte

Byte, String or Empty

Byte

Byte

Boolean

Boolean or String

Boolean

Boolean or String

Boolean

Boolean

Integer

Byte, Boolean, Integer, String or

Empty

Integer

Byte, Boolean, Integer, String or

Empty

Integer

Integer

Boolean

Byte or Empty

Integer

Byte or Empty

Boolean

Integer

Empty

Empty

Integer

Long

Byte, Boolean, Integer, Long, String or Empty

Long

Byte, Boolean, Integer, Long, String or Empty

Long

Long

LongLong

Any integral numeric type, String or Empty

LongLong

Any integral numeric type, String or Empty

LongLong

LongLong

Single

Byte, Boolean, Integer, Single, Double, String or Empty

Single

Byte, Boolean, Integer, Single, Double, String or Empty

Single

Single

Single

Long

Double

Long

Single

Double

Double

Any integral numeric type, Double, String or Empty

Any integral numeric type, Double, String or Empty

Double

String

String or Empty

String

String or Empty

String

String

Currency

Any integral or floating-point

numeric type, Currency, String or Empty

Currency

Any integral or floating-point

numeric type, Currency, String or Empty

Currency

Currency

Date

Any integral or floating-point numeric type, Currency, String, Date or Empty

Date

Any integral or floating-point numeric type, Currency, String, Date or Empty

Date

Date

Decimal

Any numeric type, String, Date or

Empty

Decimal

Any numeric type, String, Date or

Empty

Decimal

Decimal

Null

Any numeric type, String, Date, Empty, or Null

Null

Any numeric type, String, Date, Empty, or Null

Null

Null

Error

Error

Error

Error

Any type except Error

Runtime error 13 (Type mismatch) is raised.

Any type except Error

Error

Runtime error 13 (Type mismatch) is raised.

 

§ Relational comparisons can test whether operands are considered equal or if one operand is considered less than or greater than the other operand. Such comparisons are governed by the following rules, based on the effective value type:

Effective Value Type

Runtime Semantics

Byte, Integer, Long, LongLong, Currency, Decimal

The numeric values of the operands are compared. Operands MUST match exactly to be considered equal.

Single or Double

The floating-point values of the operands are compared according to the rules of IEEE 754 arithmetic. If either operand is the special value NaN, runtime error 6 (Overflow) is raised.

Boolean

The Boolean values are compared. True is considered less than False.

String

The String values are compared according to the Option Compare comparison mode (section 5.2.1.1) setting of the enclosing module as follows:

§ If the active Option Compare comparison mode is binary-compare-mode (section 5.2.1.1), each byte of the implementation-specific representation of the string data is compared, starting from the byte representing the first character of each string. At any point, if one point is not equal to the other byte, the result of comparing those bytes is the overall result of the comparison. If all bytes in one string are equal to their respective bytes in the other string, but the other string is longer, the longer string is considered greater. Otherwise, if the strings are identical, they are considered equal.

§ If the active Option Compare comparison mode is text-compare-mode (section 5.2.1.1), the text of the strings is compared in a case-insensitive manner according to the platform’s host-defined regional settings for text collation.

Null

The result is the value Null.

Error

If both Error values are standard error codes, their numeric values

(between 0 are 65535) are compared. If either value is an implementation-defined error value, the result of the comparison is undefined.

 

§ There is an exception to the rules in the preceding table when both operands have a declared type of Variant, with one operand originally having a value type of String, and the other operand originally having a numeric value type. In this case, the numeric operand is considered to be less than (and not equal to) the String operand, regardless of their values.