Skip to content

math

Description

The math block performs simple mathematical operations on numeric values provided to its input. Depending on the operation parameter, it can calculate an average, sum, minimum, maximum, or difference.

The block has one output. Multiple signal sources can be connected to the input, but the required number of connections depends on the selected operating mode.

The block accepts only numeric values. Boolean values, text values, dates, and other values that cannot be read as numbers do not take part in calculations.

Configuration parameters

Parameter name Value
Operation mode (operation) Required parameter specifying the type of calculation. Allowed values are: avg, diff_smaller_than_bigger, diff_tags, max, min, sum.
Block duplicated value (filter_duplicated_values) Required boolean value true or false. When set to true, the block does not emit another output value identical to the last emitted one. When set to false, the result is sent after every recalculation, even if it is the same as the previous one.

Meaning of the operation parameter:

  • avg: arithmetic mean of all successfully read numeric values
  • diff_smaller_than_bigger: difference between the larger and the smaller of two input values, always non-negative
  • diff_tags: difference tag1 - tag2
  • max: largest successfully read numeric value
  • min: smallest successfully read numeric value
  • sum: sum of all successfully read numeric values

Input handling

The block recalculates the result after every input change. For the input where the new value has just arrived, this new value is used. For all remaining connections, their last remembered values are used.

Only numeric inputs of integer, floating-point, temperature, or percentage type are supported. Non-numeric values are ignored or cause no result to be produced, depending on the selected mode:

  • in avg, max, min, and sum modes, each non-numeric value is simply skipped
  • in diff_smaller_than_bigger and diff_tags modes, both values must be numeric; if either of them cannot be read as a number, the result is not produced

Connection requirements:

  • for avg, max, min, and sum, at least one block must be connected to the input; more than two connections are allowed
  • for diff_smaller_than_bigger, exactly two input connections are required
  • for diff_tags, exactly two input connections are required, and they must be exactly the tag1 and tag2 lines

Inputs labeled using the tag block are meaningful only in diff_tags mode.

Input number and name Input description
tag1: First difference operand. Used only in diff_tags mode. The value from this input is used as the left side of the operation tag1 - tag2.
tag2: Second difference operand. Used only in diff_tags mode. The value from this input is subtracted from tag1.

Additional operating rules:

  • avg calculates the average only from inputs whose values can be read as numeric
  • sum adds only valid numeric values
  • max and min consider only valid numeric values
  • if there is not a single valid numeric value in avg, sum, max, or min mode, the output becomes null
  • if one of the required numeric values cannot be read in diff_smaller_than_bigger or diff_tags mode, the output becomes null

Precision and result type

The block performs calculations using the internal numeric representation with precision up to 3 decimal places.

Precision rules:

  • sum, max, min, diff_smaller_than_bigger, and diff_tags return an exact result within this precision
  • avg divides the sum of values by the number of valid inputs using integer division on the internal representation, so the result is truncated to at most 3 decimal places; the block does not apply any additional rounding

Result type and unit:

  • the output is returned as a regular numeric value of type integer or double
  • if the result has no fractional part, the block returns an integer
  • if the result has a fractional part, the block returns a floating-point value
  • input units such as temperature or percentage are not preserved at the output

Block outputs

The block has one output.

The output carries the result of the calculation selected by the operation parameter. If the result cannot be determined according to the rules of the selected mode, the output becomes null.

Block status description

The description shown below the block contains the textual representation of the last calculated result.

Examples:

  • 25
  • 18.5
  • 0

If the last result cannot be represented as text, the description becomes Unknown value.. This happens, among other cases, when the current result is null.

Errors returned by the block

The block can show the following error messages:

Error code Error description
Failed read operation. The operation parameter is missing in the configuration or cannot be read as text.
Invalid operation. The operation parameter has a value outside the supported list.
Missing filter_duplicated_values configuration. The filter_duplicated_values parameter is missing in the configuration.
Input disconnected. No other block is connected to the block input.
Diff requires two connections. diff_smaller_than_bigger mode was selected, but there are not exactly two connected input sources.
Tag1 and tag2 required. diff_tags mode was selected, but the required tag1 and tag2 lines are not both connected, or one of them is no longer available.

Usage examples

  • If operation = sum and the available input values are 2, 3.5, and 4, the output becomes 9.5.
  • If operation = avg and the valid input values are 1, 2, and 2, the output becomes 1.666.
  • If operation = max and the block receives 21, 18, and the text open, the text value is ignored and the output becomes 21.
  • If operation = diff_smaller_than_bigger and the two input values are 7 and 10, the output becomes 3.
  • If operation = diff_tags, tag1 = 24.5, and tag2 = 20, the output becomes 4.5.
  • If operation = min, but all inputs have non-numeric values, the output becomes null and the block description changes to Unknown value..