Syntax @Evaluate() Arguments The expression may contain any of these operators: feature variable references (using the value-of operator &); transfer variables; or calls to other functions. Range: Any Valid Expression Description This function evaluates an arithmetical expression and returns the result. The operators permitted in the expressions to be evaluated are a subset of the operators permitted in C expressions. They have the same meaning and precedence as the corresponding C operators. Tip: If the expression contains spaces or nested parentheses, it should be placed in quotes. Expressions frequently yield numeric results, such as integer or floating- point values. For example, the expression: @Evaluate("8.2 + 6") returns 14.2. @Evaluate is based on the Tool Command Language (TCL, version 8.4.12) expr command, as is the documentation below. TCL and its documentation is copyrighted by the Regents of the University of California, Sun Microsystems, Inc., and other parties. However, the TCL authors have granted permission to any party to reuse and modify the code and documentation, provided the original copyright holders are acknowledged. Operands An expression consists of a combination of operands, operators, and parentheses. White space may be used between the operands, operators, and parentheses as it is ignored by the expression processor. Where possible, operands are interpreted as integer values. Integer values may be specified in decimal which is the normal case, in octal if the first character of the operand is 0, or in hexadecimal if the first two characters of the operand are 0x. If an operand does not have one of the integer formats given above, then it will be treated as a floating-point number if possible. Floating- point numbers may be specified in any of the ways accepted by an ANSI- compliant C compiler, except that "f", "F", "l", and "L" suffixes are not permitted in most installations. For example, all of the following are valid floating-point numbers: 2.1, 3., 6e4, 7.91e+16. If no numeric interpretation is possible, then an operand is left as a string and only a limited set of operators may be applied to it. Operands may be specified in any of the following ways: As a numeric value, either integer or floating-point. As a value of an attribute, using standard & notation. The attribute's value is used as the operand. As an FME feature function, such as @Area(). The function is evaluated and the result used as the operand. As a mathematical function whose arguments have any of the above forms for operands, such as sin(&x). See the table below for a list of defined mathematical functions. Operators The valid operators listed below are grouped in decreasing order of precedence: - + ~ ! 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. * / % Multiply, divide, remainder. None of these operands may be applied to string operands, and remainder may be applied only to integers. The remainder always has the same sign as the divisor and an absolute value smaller than the divisor. + - Add and subtract. Valid for any numeric operands. << >> Left and right shift. Valid for integer operands only. < > <= >= Boolean less, greater, less than or equal, and greater than or equal. Each operator produces 1 if the condition is true, 0 otherwise. These operators may be applied to strings as well as numeric operands, in which case string comparison is used. == != Boolean equal and not equal. Each operator produces a zero/one result. Valid for all operand types. & 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 1 result if both operands are non-zero, 0 otherwise. Valid for numeric operands only (integers or floating-point). || Logical OR. Produces a 0 result if both operands are zero, 1 otherwise. Valid for numeric operands only (integers or floating-point). x?y:z If-then-else, as in C. If x evaluates to non-zero, then the result is the value of y. Otherwise, the result is the value of z. The x operand must have a numeric value. - + ~ ! 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. * / % Multiply, divide, remainder. None of these operands may be applied to string operands and remainder may be applied only to integers. The remainder always has the same sign as the divisor and an absolute value smaller than the divisor. See the C 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: @Evaluate("4*2 < 7") returns 0. Math Functions @Evaluate supports the following mathematical functions in expressions: acos cos hypot sinh asin cosh log sqrt atan exp log10 tan atan2 floor pow tanh ceil fmod sin Each of these functions invokes the C math library function of the same name. Refer to the C Manual entries for the library functions for details on what they do. @Evaluate also implements the following functions for conversion between integers and floating-point numbers: abs(arg) Returns the absolute value of arg. Arg may be either integer or floating- point, and the result is returned in the same form. double(arg) If arg is a floating value, returns arg. Otherwise converts arg to floating point and returns the converted value. int(arg) If arg is an integer value, returns arg. Otherwise converts arg to integer by truncation and returns the converted value. round(arg) If arg is an integer value, returns arg. Otherwise converts arg to integer by rounding and returns the converted value. Types, Overflows, Precision All internal computations involving integers are done with C-type long, and all internal computations involving floating-point are done with C-type double. When converting a string to floating-point, exponent overflow is detected and results in an error. For conversion to integer from string, detection of overflow depends on the behaviour of some routines in the local C library, so it should be regarded as unreliable. In any case, integer overflow and underflow are generally not reliably detected for intermediate results. Floating-point overflow and underflow are detected to the degree supported by the hardware, which is generally reliable. Conversion among internal representations for integer, floating-point, and string operands is automatically done as needed. For arithmetical computations, integers are used until some floating-point number is introduced, after which floating-point is used. For example, @Evaluate("5 / 4") returns 1, while @Evaluate("5 / 4.0") @Evaluate("5 / (4 + 0.0)") both return 1.25. Floating-point values are always returned with a "." or an "e" so that they will not look like integer values. For example, @Evaluate(20.0/5.0) returns "4.0", not "4". Seventeen digits of precision are always used for floating point calculations.