#### 20.2.5 Offset Operations

Poke supports a little algebra for offsets.

#### 20.2.5.1 Addition and subtraction

The addition or subtraction of two offsets results in another offset.
Examples:

(poke) 1#B + 1#b
9#b
(poke) 2#KB - 1024#B
1024#B

The unit of the result is the greatest common divisor of the units of
the operands. The result offset is not a referring offset.

The operators `++`

and `--`

, in their prefix and suffix
versions, can be applied to offsets as well. The step used in the
increment/decrement is one unit.

#### 20.2.5.2 Multiplication by a scalar

Multiplying an offset by a magnitude gives you another offset.
Examples:

(poke) 8#b * 2
16#b
(poke) 16#MB * 0
0#MB

The unit of the result is the same as the unit of the offset operand.
The result offset is not a referring offset.

Note that multiplying two offsets is not supported. This makes sense,
since computer memory is linear, and therefore it wouldn’t make any
sense to have units like `#B`^{2}

.

#### 20.2.5.3 Division

Dividing two offsets gives you a magnitude. Examples:

(poke) 16#b / 1#B
2
(poke) 1024#MB / 512#Mb
16

Dividing offsets is the Pokish way of converting memory magnitudes
between different units: just use units like you do when doing physics
or working with units in other contexts.

For example, using the syntactic trick of omitting the magnitude (in
which case it is assumed to be 1) it is very natural to write
something like the following to convert from kilobits to bytes:

There is also a ceil-division operator for offsets, with the same
semantics as the ceil-division for integers:

#### 20.2.5.4 Division by an integer

Dividing an offset by an integer gives you an offset. Example:

The unit of the result is the unit of the offset operand. The result
offset is not a referring offset.

#### 20.2.5.5 Modulus

The modulus of two offsets gives you another offset with the expected
semantics. Examples:

(poke) 9#b % 1#B
1#b
(poke) 1#B % 9#b
8#b

The unit of the result is the greatest common divisor of the units of
the operands. The result offset is not a referring offset.