Math
Synopsis
Performs mathematical operations on numeric values.
Schema
- math:
field: <ident>
operation: <string>
left_operand: <string>
right_operand: <string>
precision: <numeric>
description: <text>
if: <script>
ignore_failure: <boolean>
ignore_missing: <boolean>
on_failure: <processor[]>
on_success: <processor[]>
tag: <string>
Configuration
The following fields are used to define the processor:
| Field | Required | Default | Description |
|---|---|---|---|
field | Y | - | Target field to store the calculation result |
operation | Y | - | Mathematical operation to perform |
left_operand | Y | - | First operand value or field reference |
right_operand | N | - | Second operand value or field reference (required for binary operations) |
precision | N | 0 | Number of decimal places for rounding operations |
description | N | - | Explanatory note |
if | N | - | Condition to run |
ignore_failure | N | false | Continue processing if calculation fails |
ignore_missing | N | false | Skip if referenced fields don't exist |
on_failure | N | - | Error handling processors |
on_success | N | - | Success handling processors |
tag | N | - | Identifier |
disabled | N | false | When true, the processor is skipped and the event continues to the next one. Lets you take a processor out of the path without removing its configuration |
This operand is resolved by getNumericValue, which accepts exactly two forms: a numeric literal such as 3600, or a bare field path such as stats.total. Nothing else is evaluated.
There is no expression evaluator here, and no template expansion. "a / b" is looked up as a field literally named a / b, and "{{price}}" as a field literally named {{price}} — both fail with field does not exist. To compute a value first, use a math processor and reference the field it writes.
Supported Operations
Binary Operations (two operands)
| Operation | Aliases | Description |
|---|---|---|
add | + | Addition |
subtract | - | Subtraction |
multiply | * | Multiplication |
divide | / | Division |
modulo | % | Remainder after division |
pow | ^ | Exponentiation (power) |
min | - | Minimum of two values |
max | - | Maximum of two values |
bit_and | - | Bitwise AND |
bit_or | - | Bitwise OR |
bit_xor | - | Bitwise XOR |
shift_left | - | Left shift, by the number of positions in the right operand |
shift_right | - | Right shift, by the number of positions in the right operand |
Unary Operations (one operand)
| Operation | Description |
|---|---|
abs | Absolute value |
sqrt | Square root |
ceil | Round up to nearest integer |
floor | Round down to nearest integer |
round | Round to nearest integer or decimal places (using precision) |
bit_not | Bitwise NOT of the left operand |
Details
Performs mathematical operations on numeric values and stores the result in a target field. The processor supports both binary operations (requiring two operands) and unary operations (requiring a single operand).
Numeric values are converted for calculation: an operand may be a number, a numeric string, or a boolean (true is 1, false is 0). An operand is either a numeric literal or a field reference and nothing more — field1 / field2 is not an expression, it is a lookup for a field with that exact name. Chain a second math processor when you need a compound calculation.
The processor can extract values from existing fields, use literal numeric values, and applies appropriate error handling for mathematical edge cases like division by zero or invalid operations.
Bitwise and shift operations
The five bitwise operations and bit_not read native 64-bit integers rather than going through the float64 arithmetic path, so they keep full precision beyond 2^53 where the other operations would not. The result is an integer.
A shift count is masked to 6 bits, following C#/Kusto 64-bit semantics: shifting by 64 is a shift by 0, not a shift to zero as Go's own saturating shift would give. A negative shift count is an error.
Some operations have mathematical constraints and will fail in certain conditions:
- Division or modulo by zero
- Square root of negative numbers
- 0 raised to the power of 0 (indeterminate)
- Negative numbers raised to non-integer powers
Always provide appropriate error handling for operations that might encounter these edge cases.
Examples
Basic
Performing addition with literal values... | |
calculates and stores the result: | |
Field-Based
Calculating percentage from field values... | |
computes disk usage percentage: | |
Unary
Applying unary operations... | |
calculates absolute value: | |
Precision Rounding
Rounding to specified decimal places... | |
rounds to two decimal places: | |
Complex
Combining operations in a pipeline... | |
calculates area in multiple steps: | |
Error Handling
Handling potential calculation errors... | |
continues execution: | |