Re: MATH_MOD: Include in GLib?
- From: Sven Neumann <sven gimp org>
- To: drlion-dated-1091219837 02c327 deepwood net
- Cc: gtk-devel-list gnome org
- Subject: Re: MATH_MOD: Include in GLib?
- Date: 26 Jul 2004 10:43:21 +0200
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
] [Thread Prev