Skip to main content

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

See Also

FeedbackOpens in a new tab