The minimal residue of
is the value
or
,
whichever is smaller in absolute value, where
. If
(so that
), then the minimal residue is taken as
. The table below illustrates the common
(positive) and minimal residues for 0, 1, 2, and 3 (mod 4).
common residue | minimal residue | |
0 | 0 | 0 |
1 | 1 | 1 |
2 | 2 | |
3 | 3 |
The minimal residue is implemented in the Wolfram Language as Mod[a, m, -m/2].