Expressions are anything that results in a value. Variable references are expressions as well as functions and literal values. Multiple expressions can occur on a single line joined together by operators and the are group by terms and operator precedence.
Algebraic expressions operate on arrays of basic numeric types. There are nine main algebraic operators: multiply, divide, exponent, plus, minus, modulus, less-than selection, greater-than selection, and negative. All of the operators except negative take two operands. Also, in general, both operands should be the same type. If they are not, NCL attempts to coerce them to identical types. If this fails, a type mismatch error is generated. Additionally, either the operands must have the same number of dimensions and dimension sizes, or one operand can be a scalar value. The operators operate on the entire array of data.
The following is a list of the operator characters. The operators are listed in order of precedence: the first one has the highest precedence. The precedence rules can be circumvented by using parentheses '(' ')' around expression that should be computed first.
- Negative ^ Exponent * Multiply / Divide % Modulus + Plus - Minus < Less-than selection > Greater-than selection
The negative operator negates the value of its operand. The operand can be any numeric type. If it is an array, each element of the array is negated.
The left operand is "raised" to the power of the right operand. If the left operand is negative, then the right side must be positive. Currently, NCL doesn't support imaginary numbers; it generates an error in this situation. The result type of this operator is always a floating point number unless double precision values are used.
Multiplies left operand by right operand. No special conditions or restrictions.
Logical expressions are formed by relational operators. There are ten relational operators: less-than-or-equal, greater-than-or-equal, less-than, greater-than, equal, not-equal, and, or, exclusive-or, not. All of these operators yield logical type results. And, or, exclusive-or, and not require logical operands, and the rest accept any type.
All of the logical expressions function similarly with respect to comparisons between arrays and arrays, arrays and scalars, and scalars and scalars. For array operands, each corresponding element is compared and the result is an array of logical values the size of the operands. A single scalar can be compared against each element in an array. The result is an array of logical values the size of the array operand. Finally, when two scalars are compared, the result is a scalar logical value.
The following is a list of the logical operators and their precedence.
.le. Less-than-or-equal .lt. Less-than .ge. Greater-than-or-equal .gt. Greater-than .ne. Not-equal .eq. Equal .and. And .xor. Exclusive-or .or. Or .not. Not
The following are examples of array expressions.
(/ 1, 2, 3, 4, 5 /) (/ (/ 1, 2, 3 /)^2, (/ 4, 5, 6 /)^3,(/ 7, 8, 9 /)^4 /) (/ a - b, b + c, c / d /)
NG4 Home, Index, Examples, Glossary, Feedback, Ref Contents, Ref WhereAmI?