Skip to main content

MODS

Modulo division of corresponding elements in two dynamic arrays (zero divide not allowed).

Synopsis

MODS(dynarray1,dynarray2)

Arguments

dynarray An expression that resolves to a dynamic array of numeric values.

Description

The MODS function divides the value of each element in dynarray1 by the corresponding element in dynarray2. It then returns a dynamic array containing the modulo (remainder) for each element that results from these divisions. If an element is missing or has a null string or a non-numeric value, MODS parses its value as 0 (zero).

Attempting to divide by zero generates a <DIVIDE> error, ending execution of the function and invoking an error trap handler, if available. This is the same 0 divisor behavior as the DIVS function. In contrast, when the corresponding MODSZ or DIVSZ functions encounter a 0 divisor, they return 0 for that element.

If the two dynamic arrays have different numbers of elements, the returned dynamic array has the number of elements of the longer dynamic array. By default, the shorter dynamic array is padded with 0 value elements for the purpose of the arithmetic operation. You can also use the REUSE function to define behavior when specifying two dynamic arrays with different numbers of elements.

You can use the MOD function or the REM function to perform modulo division on single values.

You can use the NUMS function to determine if the elements in a dynamic array are numeric. You can use the ADDS (addition), SUBS (subtraction), MULS (multiplication), DIVS or DIVSZ (division), and PWRS (exponentiation) functions to perform other arithmetic operations on the corresponding elements of two dynamic arrays.

Examples

The following example uses the MODS function to return the modulo value for each division operation on the elements of two dynamic arrays:

a=11:@VM:22:@VM:0:@VM:-7
b=10:@VM:.5:@VM:10:@VM:42
PRINT MODS(a,b);  ! returns 1ý0ý0ý-7

See Also

FeedbackOpens in a new tab