﻿ MOD()

# 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

 dividend evaluates to a number or a numeric array.

 divisor evaluates to a number or a numeric array.

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.

 Dividend Divisor MOD() 530 100 30 -530 100 70 530 -100 -70 -530 -100 -30 0 100 0 0 -100 0 100 0 100 -100 0 -100

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.