Mod

Mod

%Mod function


Old name

%ModI

Function

The function returns the remainder from the division arg1/arg2. The result is an integer value.

Declaration

INT %Mod( INT in Arg1, INT in Arg2 )

Parameters

Arg1

Dividend.

Arg2

Divisor.

Description

The %Mod function calculates the modulo, meaning the remainder after integer division.

Result := %Mod(Arg1, Arg2)

The result always has the same sign as the divisor Arg2, or it is zero.

Examples

%Mod(10, 3) -- result is 1 %Mod(11, 4) -- result is 3 %Mod(-10, 3) -- result is 2 %Mod(10, -3) -- result is -2 %Mod(-10,-3) -- result is -1

The following relationship applies:

Arg1 = (Arg1 / Arg2) * Arg2 + %Mod(Arg1, Arg2)

For %Mod, the division is interpreted so that the resulting remainder has the same sign as the divisor.