ArrayOp2

(Engine-Level Function)

Description: Performs a mathematical operation on an array with respect to another array.
Returns: Nothing
Usage: Script only.
Function Groups: Array
Related to: ArrayOp1 | ArraySize | FFT| Array Functions | WhileLoop
Format: ArrayOp2(DestinationElement, SourceElement, N, OpCode[, MaskElement])
Parameters:  
DestinationElement
Required. Any array element giving the starting point for the array operation in the destination array.
The subscript for the array may be any numeric expression. If processing a multidimensional array, only the right-most dimension is used.
SourceElement
Required. Any array element giving the starting point for the array operation in the source array.
The subscript for the array may be any numeric expression.
N
Required. Any numeric expression giving the number of array elements to compute. N will be limited to the minimum of (N, Source length, Destination length).
If the starting point given by the first parameter is not the first element, and therefore N extends past the upper bound of the lowest array dimension, this computation will "wrap-around" and resume at the first element. Because N is automatically limited by the smallest array dimension, no element will be processed twice.
OpCode

Required. Any numeric expression giving the operation number to perform as follows (note that A is an element of Array1 and B is an element of Array2):

OpCode

Operation

OpCode

Operation

0

A = B

17

A = XOR(A,B)

1

A = A + B

18

A = Pow(B,A)

2

A = A - B

19

A = Exp(B*A)

3

A = B - A

20

A = B * Log(A)

4

A = A * B

21

A = B * Ln(A)

5

A = A / B

22

A = Sin(B * A)

6

A = B / A

23

A = Cos(B * A)

7

A = A % B

24

A = Tan (B * A)

8

A = Min(A,B)

25

A = B * ASin(A)

9

A = Max(A,B)

26

A = B * ACos(A)

10

A = A < B

27

A = B * ATan(A)

11

A = A <= B

28

A = B * Sqrt(A)

12

A = A==B

29

A = B * Abs(A)

13

A = A >= B

30

A = (Index of A) + B

14

A = A > B

31

A = (Index of A) * B

15

A = AND (A,B)

32

A = B * Round(A)

16

A = OR(A,B)

33

Valid(A) != Valid(B) ||

    PickValid(A != B, 0)

MaskElement

Optional. The starting element in an array of TRUE and FALSE values, specifying which elements in array, A will be operated upon. The ArrayOp function will only apply to element A[i] if Mask[starting element + i] is a valid TRUE.

Comments:

The ArrayOp2 statement is useful for large amounts of repetitive computation. While this can be done by executing a script repeatedly using WhileLoop, the ArrayOp2 statement is much faster. Complex computations may be broken down into a series of simple steps and handled by multiple ArrayOp1 and ArrayOp2 statements. If text arrays are used, each text value will be converted to a number before the numerical operations are performed. The resulting array is converted back to text.
Mode 33 will compare for differences. It does a more thorough comparison than a simple A != B.

For a multi-dimensional array such as A[X][Y], only the right-most dimension is processed. ([Y] in this example.) You must resort to loops to process the other array dimensions.

Example:

  If 1 Main;
  [
    Destination = New(ArraySize(Source));
    ArrayOp2(Destination[0], Source[0], ArraySize(Source), 0 {copy});
  ]

This example creates a copy of the array, Source.