ADS Arithmetic Expressions

An arithmetic expression is a variable term that can be a simple or compound arithmetic operation. An arithmetic expression can be used as a variable wherever the command syntax specifies
. The elements allowed in an arithmetic expression are summarized in the table below. Arithmetic expressions are composed of operands, binary operations, and unary operations.
The elements of each entity are listed below.
Arithmetic Expression Elements
Binary operators
Unary operators
Variable data fields
Addition [+]
Plus [+]
Numeric constants
Subtraction [-]
Minus [-]
Built-in functions
Multiplication [*]
Division [/]
  • Any number of parentheses can be included in the expression to indicate order of evaluation.
  • Parentheses can be nested.
  • -
    The unary minus operator. It reverses the sign of the operand that follows it.
  • arithmetic-function
    For a list of arithmetic built-in functions, see ADS Reference Built-in Functions.
  • variable
    A user-defined variable data field.
    The named variable must contain a number and can be any of the following:
    • A field on a map
    • A numeric variable
    • An element in a group
    • An element in an array
  • numeric-constant
    A number.
  • system-supplied-data-field-name
    See "System-supplied data field names" in Variable Data Fields
  • arithmetic-expression
    An arithmetic expression. Use parentheses to control the order in which operations are to be performed.
  • + - * /
    The arithmetic operators:
What it does
Syntax Arithmetic-Expression
                          ┌─ + ─┐                           ├─ - ─┤                           ├─ * ─┤      ┌────────────────────┴─ / ─┴───────────────────────┐ ►►───▼──┬─────┬───┬─ 
 ─────────────┬─┴─────────────────────►◄         └─ - ─┘   ├─ 
 ───────────────────┤                   ├─ 
 ────────────────┤                   ├─ 
 ─┤                   └─ 
Coding Considerations
The following considerations apply to coding arithmetic expressions:
  • An arithmetic expression must begin with a left parenthesis, a unary operator, or an operand.
  • An arithmetic expression must end with a right parenthesis or an operand.
  • An arithmetic expression does not require a binary operation.
  • Each left parenthesis must be followed later in the expression by a corresponding right parenthesis.
  • Operands and binary operators must be separated by at least one space from the operand or operator that follows. Parentheses do not require surrounding spaces.
  • Operands can be followed by a right parenthesis, any binary operator, or can be the end of the expression.
  • Any binary operator can be followed by an operand, a unary operator, or a left parenthesis.
  • A unary operator can be followed by an operand or a left parenthesis.
  • A left parenthesis can be followed by an operand, a unary operator, or another left parenthesis.
  • A right parenthesis can be followed by any binary operator, another right parenthesis, or can be the end of the expression.