Compute a modulo with a non-negative result ("positive modulo").
In C++, the % operator can yield negative remainders if the dividend is negative, which is unsuitable for indexing arrays. This helper ensures the result is always in the range [0, m-1].
- Parameters
-
| a | The integer value (can be negative). |
| m | The modulus (must be positive). |
- Returns
- int64_t The remainder of a divided by m, guaranteed non-negative.
- Note
- Commonly used to wrap seasonal indices in Holt-Winters, ensuring valid access into the seasonal component array.
int64_t postmod(int64_t a, int64_t m)
Compute a modulo with a non-negative result ("positive modulo").
Definition: fx_stats_util.cc:63