Modulo
Synopsis
Calculates the remainder after division of two numeric values.
Schema
- modulo:
field: <ident>
left_operand: <string>
right_operand: <string>
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 remainder result |
left_operand | Y | - | Dividend (numerator) - can be a literal value or field reference |
right_operand | Y | - | Divisor (denominator) - can be a literal value or field reference |
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 |
Details
Calculates the remainder when dividing the left operand by the right operand and stores the result in the target field. The processor uses floating-point modulo calculation to handle both integer and decimal values.
The modulo operation uses floating-point division, which means it can handle both integer and non-integer values. For integer division, consider using a combination of the divide
and floor
operations.
The processor is useful for cyclic calculations, determining if numbers are divisible evenly, and implementing various bucketing or grouping logic.
Division by zero will cause the processor to fail unless ignore_failure
is set to true
. Always validate the right operand or provide proper error handling to avoid this error.
Examples
Basic
Calculating remainder with literal values... |
|
calculates and stores the result: |
|
Divisibility
Determining if a number is divisible by another... |
|
and flagging divisibility status: |
|
Time Cycles
Mapping time-of-day to cycle position... |
|
for 12-hour clock formatting: |
|
Data Partitioning
Assigning requests to backend servers... |
|
distributes load with consistent hashing: |
|