# Compound Arithmetic and Assignment

Compound arithmetic and assignment statements combine an arithmetic operation and assignment, replacing a statement such as

` x = x op y;`

with the more compact compound form

` x op= y;`

For example, `x = x + 1;`

may be replaced with `x += 1;`

. This works for all types that support arithmetic, including the scalar types `int`

, `real`

, `complex`

, the real matrix types `vector`

, `row_vector`

, and `matrix`

, and the complex matrix types, `complex_vector`

, `complex_row_vector`

, and `complex_matrix`

.

## Compound addition and assignment

Compound addition and assignment works wherever the corresponding addition and assignment would be well formed.

`void`

`operator+=`

`(T x, U y)`

`x += y`

is equivalent to `x = x + y`

. Defined for all types `T`

and `U`

where `T = T + U`

is well formed.

*Available since 2.17, complex signatures added in 2.30*

## Compound subtraction and assignment

Compound addition and assignment works wherever the corresponding subtraction and assignment would be well formed.

`void`

`operator-=`

`(T x, U y)`

`x -= y`

is equivalent to `x = x - y`

. Defined for all types `T`

and `U`

where `T = T - U`

is well formed.

*Available since 2.17, complex signatures added in 2.30*

## Compound multiplication and assignment

Compound multiplication and assignment works wherever the corresponding multiplication and assignment would be well formed.

`void`

`operator*=`

`(T x, U y)`

`x *= y`

is equivalent to `x = x * y`

. Defined for all types `T`

and `U`

where `T = T * U`

is well formed.

*Available since 2.17, complex signatures added in 2.30*

## Compound division and assignment

Compound division and assignment works wherever the corresponding division and assignment would be well formed.

`void`

`operator/=`

`(T x, U y)`

`x /= y`

is equivalent to `x = x / y`

. Defined for all types `T`

and `U`

where `T = T / U`

is well formed.

*Available since 2.17, complex signatures added in 2.30*

## Compound elementwise multiplication and assignment

Compound elementwise multiplication and assignment works wherever the corresponding multiplication and assignment would be well formed.

`void`

`operator.*=`

`(T x, U y)`

`x .*= y`

is equivalent to `x = x .* y`

. Defined for all types `T`

and `U`

where `T = T .* U`

is well formed.

*Available since 2.17, complex signatures added in 2.30*

## Compound elementwise division and assignment

Compound elementwise division and assignment works wherever the corresponding division and assignment would be well formed.

`void`

`operator./=`

`(T x, U y)`

`x ./= y`

is equivalent to `x = x ./ y`

. Defined for all types `T`

and `U`

where `T = T ./ U`

is well formed.

*Available since 2.17, complex signatures added in 2.30*