Framework / System Layer / Formula Engine / Operators

In This Topic
    Operators
    In This Topic

    You can use operators in formulas to perform arithmetic operations (+, -, *, / and ^) or logical comparisons (<, >, =, <=, >= and <>). You also can control the order of evaluation in a formula by enclosing expressions in parentheses. The ampersand (&) operator is used for the concatenation of character strings.

    The abstraction for an operator is defined by the INOperator interface. The NFormulaEngine recognizes a predefined set of operators, which are enumerated by the OperatorType enumeration. By default when an instance of the NFormulaEngine is created it uses the default set of operators, which can be obtained from the DefaultOperators static field.

    You can override the default operators by setting the CustomOperators property to an instance of the NOperatorContainer class, which contains your custom operators. A reference to the currently used set of operators can be obtained from the UsedOperators property. If custom operators are not used it returns the DefaultOperators.

    When the operator arguments are of different type an automatic type conversion is attempted, whenever some of the arguments type do not match the action, which the operator performs. For example, the multiplication operator requires numeric arguments, and the ampersand (string concatenation) operator requires string arguments. 

    Following is detailed information about the different types of operators.

     Arithmetic Operators

    Arithmetic operators perform operations on numeric variants. The arithmetic operators arguments are automatically converted to compatible types (for example if you attempt to multiply a float variant with a double variant, the resulting variant will be of type double). The following table summarizes the current set of arithmetic operators:

    Syntax Name Description Example Result
    + Unary plus Does nothing - it is defined for completeness with the unary minus. +10 10
    - Unary minus Used to establish a number with a negative sign. -10 -10

    ^

    Exponentiation

    Raises arg1 to the power of arg2.

    10 ^ 2

    100

    *

    Multiplication

    Multiplies arg1 by arg2.

    10 * 2 20

    /

    Division

    Divides arg1 by arg2.

    10 / 2

    5

    +

    Addition

    Adds arg2 to arg1.

    10 + 2

    12

    -

    Subtraction

    Subtracts arg2 from arg1.

    10 - 2

    8

     Comparison Operators

    Comparison operators are used to construct logical expressions. A logical expression evaluates to a boolean variant with value true or false. The following table summarizes the current set of comparison operators:

    Syntax Name Description Example Result

    >

    Greater than

    Returns true if arg1 is greater than arg2. Otherwise returns false.

    10 > 2

    true

    <

    Less than

    Returns true if arg1 is less than arg2. Otherwise returns false.

    10 < 2

    false

    >=

    Greater than or equal to

    Returns true if arg1 is greater than or equal to arg2. Otherwise returns false.

    10 >= 2

    true

    <=

    Less than or equal to

    Returns true if arg1 is less than or equal to arg2. Otherwise returns false.

    10 <= 2

    false

    =

    Equal to

    Returns true if arg1 is equal to arg2. Otherwise returns false.

    10 = 2

    false

    <>

    Not equal to

    Returns true if arg1 is not equal to arg2. Otherwise returns false.

    10 <> 2

    true
     Ampersand Operator
    The ampersand operator (&) is used to concatenate its arguments. You can use this operator to create new words and phrases. For example:

    "hello" & " " & "world"

    evaluates to:

    "hello world"
    See Also