- Function Mod(x, y)
Mod
Mod(
x, ! (input) numerical expression
y ! (input) numerical expression
)
Arguments
- x
A scalar numerical expression.
- y
A scalar numerical expression unequal to 0.
Return Value
The function
Mod
returns the remainder of \(x\) after division by \(|y|\).
For \(y > 0\), the result is an integer in the range \(0,\dots,y-1\) if both \(x\) and \(y\) are integers, or in the interval \([0,y)\) otherwise.
For \(y < 0\), the result is an integer in the range \(y-1,\dots,0\) if both \(x\) and \(y\) are integers, or in the interval \((y,0]\) otherwise.
Example
_p_returnA := mod( 8, 3 ); ! mod( 8, 3 ) = 2
_p_returnB := mod( 8,-3 ); ! mod( 8,-3 ) = -1
_p_returnC := mod(-8, 3 ); ! mod(-8, 3 ) = 1
_p_returnD := mod(-8,-3 ); ! mod(-8,-3 ) = -2
Note
A run-time error results if y equals 0.
The function
Mod
can be used in constraints of mathematical programs. However, nonlinear solver may experience convergence problems if \(x\) assumes values around multiples of \(y\).
See also
Arithmetic functions are discussed in full detail in Arithmetic Functions of the Language Reference.
Function
Div