Next: , Previous: , Up: Offsets   [Contents][Index]

18.2.5 Offset Operations

Poke supports a little algebra for offsets. Addition and subtraction

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

(poke) 1#B + 1#b
(poke) 2#KB - 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. Multiplication by a scalar

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

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

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 #B2. Division

Dividing two offsets gives you a magnitude. Examples:

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

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

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 Division by an integer

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

(poke) 8#B / 2
4#B Modulus

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

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

The unit of the result is the greatest common divisor of the units of the operands.

Next: , Previous: , Up: Offsets   [Contents][Index]