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 |
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 |
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 ) |
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 automatically converted to appropriate types for calculation. The processor accepts both literal values and field references for operands, and can handle expressions like field1 / field2
in the operands.
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.
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: |
|