There are two vectors of differing, yet related sizes. The larger is (2 * RESOLUTION) + INDEX_OFFSET
(e.g. 2050) and the smaller is simply RESOLUTION
(e.g. 1024). I believe it safe enough to assume that uint16_t
can be used to contain the vector index.
Iteration through the larger vector is performed by incrementing resultIndex
by 2. During each iteration, an assignment is made to the smaller vector at the index (resultIndex - INDEX_OFFSET) / 2
.
Essentially, the code relies on the assumption that, whether INDEX_OFFSET
is odd or even, the above division by 2 will always round down, regardless of architecture. For example, if resultIndex
is 0 or 1, then 0 is expected, if is it 2 or 3 then 1 is expected, and so on. Is this a safe assumption, within the parameters above?
N.B. I acknowledge the existence of 'Dividing integer types - Are results predictable?' but it does not seem to be an exact match.