----------------------------------------------------------- | Pri. | Operator | Meaning | Associativity | ----------------------------------------------------------- | 1 | ** | Exponentiation | Right to left | | | | | | ----------------------------------------------------------- | 2 | - | Unary minus | Right to left | | | + | Unary plus | Right to left | | | ! | Logical NOT | Right to left | | | | | | ----------------------------------------------------------- | 3 | * | Multiplication | Left to right | | | / | Division | Left to right | | | % | Modulus | Left to right | | | | | | ----------------------------------------------------------- | 4 | + | Addition | Left to right | | | - | Subtraction | Left to right | | | | | | ----------------------------------------------------------- | 5 | < | Less than | Left to right | | | <= | Less than or equal | Left to right | | | > | Greater than | Left to right | | | >= | Greater than or equal | Left to right | | | == | Equal | Left to right | | | != | Not equal | Left to tight | | | | | | ----------------------------------------------------------- | 6 | && | Logical AND | Left to right | | | || | Logical OR | Left to right | | | | | | ----------------------------------------------------------- Figure 3.1: OperatorsThe first column in figure 3.1 gives the precedence of an operator. This means that when two operators have different precedence, the operator with the higher precedence is evaluated first. The highest precedence is 1.
When two operators have the same precedence, they are evaluated in the direction specified in the last column 'Associativity'.
The order of normal precedence can be changed by enclosing expressions in parenthesis.
Examples:
3 * 2 + 1 | has the value 7 since the operator '*' has a higher precedence than the operator '+'. |
2 * 3 / 2 | has the value 3 since '*' and '/' are evaluated from left to right. |
2 ** 2 ** 3 | has the value 256 since '**' is evaluated from right to left. |
--------------------------------------------- | Operation | Value | --------------------------------------------- | array + array | array | | array - array | array | | array / array | array | | array * array | array | | array ** array | array | --------------------------------------------- | array + scalar | array | | scalar + array | array | --------------------------------------------- | array - scalar | array | | scalar - array | array | --------------------------------------------- | array / scalar | array | | scalar / array | array | --------------------------------------------- | array * scalar | array | | scalar * array | array | --------------------------------------------- | array ** scalar | array | | scalar ** array | array | --------------------------------------------- Figure 3.2: Array Operations
------------------------------------------------------- | | BYTE | SHORT | INT | FLOAT | DOUBLE | ------------------------------------------------------- | BYTE | BYTE | SHORT | INT | FLOAT | DOUBLE | | SHORT | SHORT | SHORT | INT | FLOAT | DOUBLE | | INT | INT | INT | INT | FLOAT | DOUBLE | | FLOAT | FLOAT | INT | FLOAT | FLOAT | DOUBLE | | DOUBLE | DOUBLE | FLOAT | DOUBLE | DOUBLE | DOUBLE | ------------------------------------------------------- Figure 3.3: Type ConversionsAdditional notes:
-------------------------------------------------------- |Scalar/Array | BYTE | SHORT | INT | FLOAT | DOUBLE | -------------------------------------------------------- | BYTE | BYTE | SHORT | INT | FLOAT | DOUBLE | | SHORT | BYTE | SHORT | INT | FLOAT | DOUBLE | | INT | BYTE | SHORT | INT | FLOAT | DOUBLE | | FLOAT | * | * | FLOAT | FLOAT | DOUBLE | | DOUBLE | * | * | FLOAT | FLOAT | DOUBLE | -------------------------------------------------------- Figure 3.4: Type Conversions between Arrays and ScalarsAdditional notes:
--------------------------------------------------------- | Function | Meaning | --------------------------------------------------------- | BYTE (x) | converts x to BYTE. | | CHAR (x) | converts x to BYTE. | | SHORT (x) | converts x to INT. | | INT (x) | converts x to INT. | | FLOAT (x) | converts x to FLOAT. If x is complex, | | | FLOAT returns the real part of x. | | DOUBLE (x) | converts x to DOUBLE. | | COMPLEX (x,y) | converts to COMPLEX. x is converted | | | to the real, y to the imaginary part. | | | The second parameter y is optional. | | STRING (x) | converts x to STRING. | --------------------------------------------------------- Figure 3.5: Type Conversion FunctionsExamples:
-------------------------------------------------------------- | Example | Meaning | -------------------------------------------------------------- | INT A[100] | | | A = FLOAT (A) | converts A to a floating point array. | -------------------------------------------------------------- | Z = COMPLEX (3, 4) | creates the complex number Z with the | | | real part 3 and the imaginary part 4. | | Z = COMPLEX (3) | creates the complex number Z with the | | | real part 3 and the imaginary part 0. | -------------------------------------------------------------- | IR = {65,66,67,68} | | | S = STRING (IR) | creates the string S = 'ABCD'. | -------------------------------------------------------------- Figure 3.6: Type Conversion Examples