Chapter 3. Operators, Casting, Expressions, Casting

3.1. Operators

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 UNIVERSAL6
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
'*'35 Multiplication Promotion2
'/'35 Division Promotion2
'%'5 Modulus division (remainder) Promotion2
'+'3 Addition Promotion2
'-'3 Subtraction Promotion2
'<<' Shift left Promotion2
'>>'1 Shift right Promotion2
'<'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 Promotion2
'|' Binary OR Promotion2
'^' Binary exclusive OR Promotion2

1shift right: If the left operand is signed, the shift is arithmetic (sign preserving). If unsigned, it is a simple binary shift.

2promotion: 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.

3These operators allow FLOAT types.

4Floating 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).

5Keep 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).

6The result of WHEREIS depends upon the identifier used: