Calculates the floor modulus of field value and the divisor, for
example, x mod y
where
y
is the divisor and
x is a field. Both the
field or divisor are floor rounded before the calculation.
Decimal values are supported.
Note
Math functions on ARM architecture may return different results in very high-precision calculationsc compared to Intel/AMD architectures.
Hide omitted argument names for this function
Omitted Argument NamesThe argument name for
field
can be omitted; the following forms of this function are equivalent:logscale Syntaxmath:mod("value",divisor="value")
and:
logscale Syntaxmath:mod(field="value",divisor="value")
These examples show basic structure only.
math:mod()
Examples
Click
next to an example below to get the full details.Calculate Floor Modulus of Values
Calculate the remainder using floor modulus with the
math:mod()
function
Query
x := 7
| math:mod(x, 3, as=remainder)
Introduction
In this example, the math:mod()
function is used to
calculate the remainder when a field value is divided by a specified
divisor
(y =
3
in this case).
Step-by-Step
Starting with the source repository events.
- logscale
x := 7
Assigns the value
7
to a field named x. This field value will be divided by the divisor in the modulus calculation. - logscale
| math:mod(x, 3, as=remainder)
Calculates the floor modulus of the field value x with divisor (
y
)3
, and returns the result in a new field named remainder. Both values are floor rounded before the calculation. If theas
parameter is not specified, the result is returned in a field named _mod as default. Event Result set.
Summary and Results
The query is used to calculate the remainder after division using floor modulus, which handles both positive and negative numbers consistently.
This query is useful, for example, to determine if numbers are divisible evenly by a specific value, to implement circular buffers, or to distribute items evenly across groups.
Sample output from the incoming example data:
remainder |
---|
1 |
The result shows that when 7
is divided by
3
, the remainder is 1
(as
7 = 2 × 3 + 1
).
The function can also handle:
Negative numbers (for example,
-7 mod 3 = 2
)Decimal values (for example,
7.8 mod 3 = 1
, as the value is floor rounded first)Decimal divisors (which are also floor rounded before calculation)