## MOD(), MODS() |

The MOD() function returns the modulus value of one value divided by another. The MODS() function is similar to MOD() but operates on successive elements of two dynamic arrays, returning a similarly structured dynamic array of results.
Format
MOD(dividend, divisor)
where
The MOD() function returns the modulus value of dividing dividend by divisor. This is defined as
MOD(x, y) = IF y = 0 THEN x ELSE x - (y * FLOOR(x / y))
where the FLOOR() function returns the highest integer with value not greater than its argument. For example, FLOOR(-3.7) is -4. (FLOOR() is not part of QMBasic. It is used here only to explain the action of the MOD() function).
The MOD() function differs from the REM() function when one of its arguments is negative. The following table shows the result of the MOD() function.
The MODS() function operates on corresponding elements of two dynamic arrays, returning a similarly structured dynamic array of results. For arrays of differing structure, the structure of the result depends on whether the REUSE() function is used.
Example
N = MOD(T, 30)
This statement finds the modulus of dividing T by 30 and assigns this to N.
See also: |