Re: MATH_MOD: Include in GLib?
- From: Jan Kratochvil <rcpt-gtk-devel-list AT gnome org jankratochvil net>
- To: Sven Neumann <sven gimp org>
- Cc: drlion-dated-1091219837 02c327 teepee ath cx, gtk-devel-list gnome org
- Subject: Re: MATH_MOD: Include in GLib?
- Date: Mon, 26 Jul 2004 13:29:29 +0200
Hi,
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))
...
> The result of "x%m" will be 0..(m-1) provided that you respect the
> fact that the modulo operator is undefined on negative operands. The
> behaviour is machine-dependent and you should simply avoid to use
> modulo with signed variables.
I was not aware the result is undefined, I still consider it a bug.
> Also note that your suggest macro won't work if x < m.
Thanks for notice, I did not check the macro (it was not mine...):
#define G_MOD(x, m) ((x) >= 0 ? (x) % (m) : (m) - 1 - ((-(x) - 1) % (m)))
Regards,
Lace
--
Jan Kratochvil; Captive: free r/w NTFS Filesystem; http://www.jankratochvil.net/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]