mod()
Returns the remainder of an integer division.
Syntax
mod(NUM_EXPR, DIVISOR)
Parameters
NUM_EXPR- The dividend of the division. Must be a 32-bit integer or 64-bit integer type.
DIVISOR- The divisor. Must be a 32-bit integer or 64-bit integer type.
Description
The mod() function returns the remainder of dividing NUM_EXPR by DIVISOR as a 64-bit integer.
Returns null in the following cases:
NUM_EXPRorDIVISORis null.NUM_EXPRorDIVISORis not an integer type (32-bit integer or 64-bit integer).DIVISORis 0 (division by zero is prevented).
Error codes
| Error code | Description |
|---|---|
| invalid-mod-args | The number of arguments is not exactly 2. |
Usage examples
To prepare the WEB_APACHE_SAMPLE table used in these examples, refer to Preparing sample data.
-
Calculate the remainder after removing the hundreds digit from the HTTP status code.
table limit=5 WEB_APACHE_SAMPLE | eval result = mod(status, 100) | fields status, result -
Dividing by zero returns null.
json "{}" | eval r = mod(5, 0) | # r: null -
NULL input
json "{}" | eval r = mod(null, 3) | # r: null
Compatibility
The mod() function is available since before Sonar 4.0.