MATH_MOD: Include in GLib?


I've been using a macro called MOD as a modulus function with
different semantics than %.  Specifically, I need -1 mod 3 to equal 2.

#define MOD(x, m) ((x) >= 0 ? (x) % (m) : (m) + (x) % (m))

I haven't really seen this used anywhere else, although I assume that
it is pretty common since it is needed for normalizing any wrapping
values -- such as angles for which, e.g., -90° = 270°.

My suggestion is that it be put in GLib right next to its more
generally applicable fellows MIN, MAX, and CLAMP.  What do you think?


Daniel Brockman
drlion deepwood net

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]