arraylib::IndexWrap

Command: arraylib::IndexWrap


Description

"IndexWrap" projects a cyclic integer index in the range (-oo oo)
of periodicy N onto its norm interval [0 N).

This function can be used to "wrap around" array indices in order to
index an array

Alternatives: Function IndexWrap_i_i (undocumented) -> behaviour and
synopsis are the same except that no warnings or error messages are
thrown.

Parameters

In : index: integer value in (-oo oo).

N: Peroidicity of the cyclic index.
"index" is projected on the half-open interval [0 N).
N must be positive (and different from 0).

Out: The cyclic equivalent of the given index regarding period N.

Author
Ruediger Kupper

Availability

"Namespace"-dictionary "arraylib".

Synopsis
index N CyclicValue -> normindex

Examples

-6 3 IndexWrap -> 0
-5 3 IndexWrap -> 1
-4 3 IndexWrap -> 2
-3 3 IndexWrap -> 0
-2 3 IndexWrap -> 1
-1 3 IndexWrap -> 2
0 3 IndexWrap -> 0
1 3 IndexWrap -> 1
2 3 IndexWrap -> 2
3 3 IndexWrap -> 0
4 3 IndexWrap -> 1
5 3 IndexWrap -> 2
6 3 IndexWrap -> 0

File
lib/sli/arraylib.sli
Diagnostics

N must be positive (and different from 0). If N <= 0 /RangeCheck is raised.
Note that the variant IndexWrap_i_i does not do this check for
efficiency and will break or yield invalid results in this case.

Remarks

This function behaves like Mathematica's Mod function (which is
different from the mathematical definition of MOD).

FirstVersion
14.2.2003 (Einstein's birthday)