Just said that you took the wrong operator.
C ++ and C are % not modulo, but the remainder.
assert(a / b * b + a % b == a);
If anon-negative, modulo and remainder are the same.
Otherwise, the return value is negative, just add b.
template<class T>
inline constexpr auto
modulo(T a, T b) -> decltype(a%b) {
auto r = a % b;
if(r<0) r += b;
return r;
}
Or (also) for C:
: ++ 11, a / b , 0, ++ 03 , , , 0.
:
Modulo - 0 <= <