Math Operators
The operators listed below are grouped in decreasing order of precedence. If any operand is null, missing, or the empty string, or the expression is invalid, the expression will return null, with the fme_expression_warnings list attribute appended to. If result values can be losslessly converted to integer values, this conversion is done. Otherwise, result values are left at double precision.
Note that when using math operators, if a null is encountered, null will be returned. To handle null properly, use the math functions instead of the operators. For example, if the attribute nullAttr has a value of null, 1+@Value(nullAttr) will return null but @add(1, @Value(nullAttr)) will return 1.
Function | Description |
---|---|
- + ~ ! |
Unary minus, unary plus, bit-wise NOT, logical NOT. None of these operands may be applied to string operands, and bit-wise NOT may be applied only to integers. |
** |
Exponentiation. Valid for numeric operands only. |
* / % |
Multiply, divide, remainder. All expressions involving the / operator will result in a floating point value. For example, 1/2 = 0.5. The expression 1/0 results in infinity. The % operator may be applied only to integers. The remainder has the same sign as the divisor (denominator) and an absolute value smaller than the divisor. |
+ - |
Add and subtract. |
<< >> |
Left and right shift. Valid for integer operands only. |
< > <= >= |
Boolean operators: less than, greater than, less than or equal, and greater than or equal. Each operator produces 1 if the condition is true, and 0 if the condition is false. These operators may be applied to string operands, in which case string comparison is used. |
== != |
Boolean operators: equal and not equal. Each operator produces a result of 1 if the condition is true, and 0 if the condition is false. Note: If used with string operands, enclose strings in braces {}. |
& |
Bit-wise AND. Valid for integer operands only. |
^ |
Bit-wise exclusive OR. Valid for integer operands only. |
| |
Bit-wise OR. Valid for integer operands only. |
&& |
Logical AND. Produces a result of 1 if the condition is true, and 0 if the condition is false. |
|| |
Logical OR. Produces a result of 1 if the condition is true, and 0 if the condition is false. |
? : (x?y:z) |
If-then-else, as in C. Example: true ? 1 : 0 If x is non-zero, then the result is the value of y, and if x evaluates to zero, the result is the value of z. |
See the Tcl expr manual for more details on the results produced by each operator. All binary operators group left-to-right within the same precedence level. For example, the expression:
4*2 < 7
returns 0.