﻿ REM()

# REM()

The REM() function returns the remainder when one value is divided by another.

Format

REM(dividend, divisor)

where

 dividend evaluates to a number or a numeric array.

 divisor evaluates to a number or a numeric array.

The REM() function returns the remainder of dividing dividend by divisor. This is defined as

REM(x, y) = SIGN(x) * MOD(ABS(X), ABS(Y))

where the SIGN() function returns 1 for x > 0, -1 for x < 0 and 0 for x = 0. (SIGN() is not part of QMBasic. It is used here only to explain the action of the REM() function).

The REM() function differs from the MOD() function when one of its arguments is negative. The following table shows the result of the REM() function.

 Dividend Divisor REM() 530 100 30 -530 100 -30 530 -100 30 -530 -100 -30 0 100 0 0 -100 0 100 0 100 -100 0 -100

If either dividend or divisor is a numeric array (a dynamic array where all elements are numeric), the REM() function operates on each element in turn and returns another numeric array. The structure of this array will be the same as that of the dividend and divisor arrays if they are identical. For arrays of differing structure, the structure of the result depends on whether the REUSE() function is used.

Example

N = REM(T, 30)

This statement finds the remainder of dividing T by 30 and assigns this to N.