DADiSP Worksheet Functions > Function Categories > Data Manipulation and Editing > += -= /= *= >>= <<= &= |= %= (Assignment Operators)

 

+= -= /= *= >>= <<= &= |= %= (Assignment Operators)

Purpose:

Operate and assign the value of an expression.

Syntax:

val1 op= val2

val1

-

A scalar, series, or table.

val2

-

A scalar, series, or table.

Returns:

A scalar, series, or table.

Example:

j = 10;

j += 2;

 

Variable j contains the value 12.

Example:

W1: {1, 2, 3, 4}

W1 += 2

 

W1 contains the series {3, 4, 5, 6}. Each value of the series is incremented by the value 2.0.

Example:

a = {1, 2, 3, 4}

a &= 0x01

 

Variable a contains the series {1, 0, 1, 0} indicating the values that have the lowest bit set.

Example:

b = {1, 2, 3, 4}

b |= 0x01

 

Variable b contains the series {1, 3, 3, 5}.

Example:

b = {1, 2, 3, 4}

b |^= 0x01

 

Variable b contains the series {0, 3, 2, 5}.

Remarks:

The following assignment operators are supported:

 

 

Operator

Description

+=

add then assign

-=

subtract then assign

*=

multiply then assign

/=

divide then assign

%=

modulo then assign

>>=

bit right shift then assign

<<=

bit left shift then assign

&=

bit and shift then assign

|=

bit or then assign

|^=

bit xor then assign

@=

append then assign

@@

concatenate

 

 

If e1 and e2 are expressions, then

 

e1 op= e2

 

is equivalent to

 

e1 = (e1) op (e2)

 

except that e1 is computed only once. Notice the parenthesis.

 

x *= y + 1

 

is equivalent to

 

x = x * (y + 1)

 

not

 

x = x * y + 1

 

Assignment operators are not only fast and concise, they correspond better to the way people think. We say "add 2 to j" or "increment j by 2," not "take j, add 2, then put the result back into j." Thus, j += 2.

 

The statement:

 

a = b @@ c

 

is more compact and equivalent to

 

a = concat(b, c)

 

The statement:

 

a @= b

 

is equivalent to

 

append(a, b)

 

The @= operator appends the series B to the end of series A in place. a @= b is much faster than a = a @@ b for large series because @= operates on the existing series whereas @@ creates and assigns a new series.

 

See DADiSP/VectorXL to optimize arithmetic operations on series.

See Also:

+ - * / ^

:= (Hot Variable Assignment)

= (Variable Assignment)

Bit Operators

DADiSP/VectorXL

Logical Operators