MOD
MOD returns the modular equivalent of the remainder of one value divided by another.
MOD returns the smallest nonnegative value, R, such that (x - R)/y = n
.
In this example, the value for n is an integer value. That is, R is the smallest nonnegative value that must be subtracted from x to make it divisible by y.
- x
- Real expression.
- y
- Real expression. If y = 0, the ZERODIVIDE condition is raised.
(min(n,p2-q2+max(q1,q2)),max(q1,q2))
In this example, (p1,q1) and (p2,q2) are the precisions of x and y, respectively, and n is N for FIXED DECIMAL or M for FIXED BINARY.
If x and y are fixed-point with different scaling factors, the argument with the smaller scaling factor is converted to the larger scaling factor before R is calculated. If the conversion fails, the result is unpredictable.
- Raise the SIZE condition if SIZE is enabled.
- Produce a negative value if SIZE is not enabled.
Example
The following example contrasts the MOD and REM built-in functions.
rem( +10, +8 ) = 2
mod( +10, +8 ) = 2
rem( +10, -8 ) = 2
mod( +10, -8 ) = 2
rem( -10, +8 ) = -2
mod( -10, +8 ) = 6
rem( -10, -8 ) = -2
mod( -10, -8 ) = 6