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.
|
The result, R, is real with the common base and scale of the arguments. If the result is floating-point, the precision is the greater of those of x and y. If the result is fixed-point, the precision is given by the following:
(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.
The following example contrasts the MOD and REM built-in functions.
For information on the REM built-in function, see REM.