Re: MATH_MOD: Include in GLib?



Hi,

Daniel Brockman <drlion deepwood net> writes:

> 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?

MIN, MAX and CLAMP don't follow the GLib naming scheme and are there
just for backward compatibility. Introducing MOD(x) is certainly not
an option. If at all it would have to be G_MOD(x). But I doubt that
the semantics of such a macro are obvious enough and that it would be
of general usefulness. Shouldn't defining it in one of your headers be
good enough?


Sven



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