Table 3-1. JALv2 Operators
Operator | Operation | Result |
---|---|---|
COUNT | returns the number of elements in an array | UNIVERSAL |
WHEREIS | return the location of an identifier | UNIVERSAL^{6} |
DEFINED | determines if an identifier exists | BIT |
'(' expr ')' | Grouping | Result of evaluating expr |
'-'^{3} | Unary - (negation) | Same as operand |
'+'^{3} | Unary + (no-op) | Same as operand |
'!' | 1's complement | Same as operand |
'!!'^{3} | Logical. If the following value is 0, the result is 0, otherwise the result is 1. | BIT |
'*'^{3}^{5} | Multiplication | Promotion^{2} |
'/'^{3}^{5} | Division | Promotion^{2} |
'%'^{5} | Modulus division (remainder) | Promotion^{2} |
'+'^{3} | Addition | Promotion^{2} |
'-'^{3} | Subtraction | Promotion^{2} |
'<<' | Shift left | Promotion^{2} |
'>>'^{1} | Shift right | Promotion^{2} |
'<'^{3} | Strictly less than | BIT |
'<='^{3} | Less or equal | BIT |
'=='^{4} | Equality | BIT |
'!='^{4} | Unequal | BIT |
'>='^{3} | Greater or equal | BIT |
'>'^{3} | Strictly greater than | BIT |
'&' | Binary AND | Promotion^{2} |
'|' | Binary OR | Promotion^{2} |
'^' | Binary exclusive OR | Promotion^{2} |
^{1}shift right: If the left operand is signed, the shift is arithmetic (sign preserving). If unsigned, it is a simple binary shift.
^{2}promotion: The promotion rules are tricky, here are the cases:
If either operand is FLOAT, the result is FLOAT. |
If one of the operands is UNIVERSAL and the other is not, the result is the same as the non-UNIVERSAL operand. |
If both operands have the same signedness and width, the result is that of the operands. |
If both operands have the same width, and one is unsigned, the result is unsigned. |
If one operand is wider than the other, the other operand will be promoted to the wider type. |
^{3}These operators allow FLOAT types.
^{4}Floating point numbers should never be compared for equality due to the imprecise way in which they are stored. Attempting to do so will result in a warning from the compiler. Two different operations which should yield an identical mathmatical result may compare unequal. The correct way to compare two floating point numbers, say A and B, is `abs((A - B)/B) < 1e-6' (floating point values have a nominal precision of 6 - 9 digits).
^{5}Keep in mind that multiplication and division, even between integer types are very expensive operations in both code size and data size (see Chapter 11: Build-in Function).
^{6}The result of WHEREIS depends upon the identifier used:
A procedure or function will return the CODE address of the entry point.
An assembly label will return the CODE address of the label.
A variable will return the DATA address of the variable.
A simple constant will generate an error.
A constant array depends upon the processor family:
16-bit: returns the CODE address of the data.
non-16 bit: returns the CODE address of the entry point to the lookup function.