Next: Offset Attributes, Previous: Casting Offsets, Up: Offsets [Contents][Index]

Poke supports a little algebra for offsets.

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 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.

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.

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}

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:

(poke) 24 #Kb/#B 3072

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

(poke) 10#B /^ 3#B 4

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

(poke) 8#B / 2 4#B

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.

Next: Offset Attributes, Previous: Casting Offsets, Up: Offsets [Contents][Index]