Knowledge Base

# Calculation Operators

Rulestar's custom calculation engine supports a range of operations and functions to assist you in performing a variety of useful calculations. Calculations can be numeric and boolean in nature.  See "Field inputs for logical and conditional operators" below to find out how different fields are treated as boolean values for use with logical operators and in functions.

### Precedence

The table below orders the operators from the highest to the lowest precedence:

 Operator Type Operators Grouping ( ) Property read and method call . Logical not Unary arithmetic negation ! not - Power ^ Multiplication Division Remainder * / % Addition Subtraction + - Greater than Greater than and equal to  Less than Less than and equal to > >= < <= Equal to Not equal to = != Logical and & and Logical or | or Conditional if then else Argument (operand) separator ,

### Logical operators

Logical operators ("and", "or" and "not") can be used to perform logic within calculations. The logical operators "and", "or" and "not" are the same as "&", "|" and "!" and are interchangeable. The logical operators can also be expressed in function form as "And()", "Or()" and "Not()" which are similar to the functions used in field logic expressions. The following expressions are equivalent:

 Operator Available Syntax AND And(1, @123, 0) 1 & @123 & 0 1 and @123 and 0 OR Or(1, @123, 0) 1 | @123 | 0 1 or @123 or 0 NOT Not(@123) !@123 not @123

All field types can be used within logical operators. See below to find out how.

### Conditional operation

The conditional operator is a ternary operator (it takes three operands). The result of the conditional operator is the result of whichever operand is evaluated — the second or the third (only one of these is evaluated). You may find this useful for performing conditional calculations within a single field.

There are three components to a conditional operator:

1. PredicateExpression - This expression is evaluated as true or false. Can be an expression using operators listed above, a literal or a field reference (will be converted to a boolean value as per "Field inputs for logical and conditional operators" below).
2. ThenExpression - If the PredicateExpression evaluates to true, this expression is evaluated and will be the result. Can be a literal, a field reference or another operation/expression.
3. ElseExpression - If the PredicateExpression evaluates to false, this expression is evaluated and will be the result. Can be a literal, a field reference or another operation/expression.

There are three valid conditional operator syntaxes:

1. PredicateExpression ? ThenExpression : ElseExpression
2. If(PredicateExpression, ThenExpression, ElseExpression)
3. if PredicateExpression then ThenExpression else ElseExpression

All field types can be used within the conditional operator. See below to find out how.

### Field inputs for logical and conditional operators

While arguments of logical operators and functions are supposed to be boolean values, any field type can be used as they are treated as boolean values using the following rules:

• hidden by logic - if a referenced field is hidden by logic, it's interpreted as false.
• unanswered fields - if a referenced field is unanswered, it's interpreted as false.
• number fields - zero is interpreted as false and any other number is interpreted as true.
• string fields - an empty string is false and non-empty is true (similar behaviour to "is answered" logic).
• date fields - any date value is interpreted as true.
• checkbox fields - if a checkbox that has more than one option has at least one option selected, it’s interpreted as true regardless of the option value, otherwise, it's interpreted as false.