Skip to main content

DIVS

Divides the corresponding elements in two dynamic arrays (zero divide not allowed).

Synopsis

DIVS(dynarray1,dynarray2)

Arguments

dynarray1 The dividend. An expression that resolves to a dynamic array of numeric values.
dynarray2 The divisor. An expression that resolves to a dynamic array of non-zero numeric values.

Description

The DIVS function divides the value of each element in dynarray1 by the corresponding element in dynarray2. It then returns a dynamic array containing the results of these divisions. If an element value is an empty string or a non-numeric value, DIVS parses its value as 0 (zero).

DIVS can return fractional numbers as the result (quotient) of a division operation. The DIV function can only return the integer portion of the result (quotient) of a division operation; the fractional portion is truncated.

The DIVS and DIVSZ functions are identical, with one difference:

  • When DIVS encounters a 0 divisor, attempting to divide by zero generates a <DIVIDE> error, ending execution of the function and invoking an error trap handler, if available.

  • When DIVSZ encounters a 0 divisor, it returns 0 for that element.

If the two dynamic arrays have different numbers of elements, by default the shorter dynamic array is padded so that the returned dynamic array has the number of elements of the longer dynamic array. If the shorter dynamic array is the dividend (dynarray1), it is padded with the required number of elements with the value of 0. If the shorter dynamic array is the divisor (dynarray2), it is padded with the required number of elements with the value of 1. You can also use the REUSE function to define behavior when specifying two dynamic arrays with different numbers of elements.

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), MODS and MODSZ (modulo division), and PWRS (exponentiation) functions to perform other arithmetic operations on the corresponding elements of two dynamic arrays.

Examples

The following example uses the DIVS function to divide the elements of two dynamic arrays:

a=11:@VM:22:@VM:0:@VM:-7
b=10:@VM:.5:@VM:10:@VM:42
PRINT DIVS(a,b)
      ! returns 1.1ý44ý0ý-.1666666666667

See Also

FeedbackOpens in a new tab