Skip to main content

This is documentation for Caché & Ensemble.

For information on converting to InterSystems IRIS, see the InterSystems IRIS Adoption Guide and the InterSystems IRIS In-Place Conversion Guide, both available on the WRC Distributions page (login required).

Previous sectionNext section

MOD

Modulo division of two values.

Synopsis

MOD(numstr1,numstr2)

Arguments

numstr1 The dividend. An expression that resolves to a number or numeric string.
numstr2 The divisor. An expression that resolves to a non-zero number or numeric string.

Description

The MOD function divides the value of numstr1 by numstr2, and returns the modulo (remainder following integer division) that results from this division. If a numstr value is the null string or a non-numeric value, MOD parses its value as 0 (zero).

Attempting to divide by zero generates a <DIVIDE> error, ending execution of the function and invoking an error trap handler, if available.

The REM function is functionally identical to the MOD function. To perform integer division, use the DIV function. To perform exact division with a fractional quotient, use the division operator (/).

You can use the MODS function to perform modulo division on the elements of a dynamic array.

Examples

The following examples use the MOD function to return the modulo value for a division operation:

PRINT MOD(10,5);   ! returns 0
PRINT MOD(10,4);   ! returns 2
PRINT MOD(10,3);   ! returns 1
PRINT MOD(10,6);   ! returns 4
PRINT MOD(10,-6);  ! returns 4
PRINT MOD(10,11);  ! returns 10
Copy code to clipboard

See Also