Re: MATH_MOD: Include in GLib?
- From: Daniel Brockman <drlion deepwood net>
- To: gtk-devel-list gnome org
- Subject: Re: MATH_MOD: Include in GLib?
- Date: Wed, 28 Jul 2004 07:28:33 +0200
Jan Kratochvil <rcpt-gtk-devel-list AT gnome org jankratochvil net> writes:
> On Mon, 26 Jul 2004 12:41:47 +0200, Sven Neumann wrote:
> > Jan Kratochvil <lace jankratochvil net> writes:
> > > On Mon, 26 Jul 2004 10:43:21 +0200, Sven Neumann wrote:
> > > > Daniel Brockman <drlion deepwood net> writes:
> > > ...
> > > > > #define MOD(x, m) ((x) >= 0 ? (x) % (m) : (m) + (x) % (m))
> > > > ...
> > > > 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).
I did not intend to imply that the macro should be named exactly `MOD'
once in GLib. I did not add the `G_' prefix simply because the macro
was not yet in GLib. I do think it should be prefixed. (Indeed,
maybe MIN, MAX, and CLAMP should even be deprecated in favor of G_MIN,
G_MAX, and G_CLAMP.)
> > Also note that your suggest macro won't work if x < m.
What do you mean? Assuming that x % m == -(-x % m) whenever x < 0
(which is allegedly machine-dependent), it works in all these cases,
as far as I can tell, and x < m in all of them:
MOD(-1, 3) == 2
MOD(-5, 3) == 1
MOD(2, 4) == 2
MOD(-137, 4242) == 4105
I get the same result with Lace's definition, although the fact that
he even created one is evidence enough that I'm the ignorant one here.
Do you mean that my macro will invoke machine-dependent behavior
whenever x < 0?
drlion deepwood net
] [Thread Prev