Compiler enhancement (edit 892): Add explicit / unambiguous comparison operators:
Operator |
Description |
Operator |
Description |
#> |
numeric greater than |
$> |
string greater than |
#>= |
numeric greater than or equal |
$>= |
string greater than or equal |
#< |
numeric less than |
$< |
string less than |
#<= |
numeric less than or equal |
$<= |
string less than or equal |
#= |
numeric equal |
$= |
string equal |
## |
numeric not equal |
$# |
string not equal |
#<> |
numeric not equal |
$<> |
string not equal |
These are equivalent to the traditional comparison operators except that instead of the type of comparison being determined by the type of the leading value, here the type of comparison is established by the relative operator, which in turn may cause the leading comparator to be converted accordingly.
These are mainly useful when working with dynstruct members, which are treated by the compiler as strings, but which may be bound at runtime to numeric variables. If you know that you are working with a variable that should be treated as a number (or will be bound to a number), then using the explict-type comparisons will force the compiler to generate the comparison that you want, rather than the code that it thinks is appropriate.
For example:
if foo.price > foo.value then ...
if foo.price #> foo.value then ...
If foo is a dynstruct, then the compiler will treat foo.price and foo.value as strings, so it will interpret the first greater than operator as a string comparison. If foo.price and/or foo.value get re-bound to numeric variables at runtime, the string-type comparison will not yield the intended result. The second statement above resolves this by forcing the compiler to generate code for a numeric comparison.
Note that these operators are purely compiler constructs and do not require a corresponding update of the runtime system.
See 6.5.1655.0 and compiler edit 890 below for analogous explicit-type addition and concatenation operators.)