Can't this just assume/require b to be positive? That would make them a lot simpler:
#define DIV(a,b) ((a) / (b) - ((a) % (b) < 0 ? (b) : 0)) #define MOD(a,b) ((a) % (b) + ((a) % (b) < 0 ? (b) : 0)) On Fri, Aug 14, 2015 at 7:06 AM, Ben Avison <bavi...@riscosopen.org> wrote: > The previous implementations of DIV and MOD relied upon the built-in / and > % > operators performing round-to-zero. This is true for C99, but rounding is > implementation-defined for C89 when divisor and/or dividend is negative, > and > I believe Pixman is still supposed to support C89. > --- > pixman/pixman-private.h | 8 ++++---- > 1 files changed, 4 insertions(+), 4 deletions(-) > > diff --git a/pixman/pixman-private.h b/pixman/pixman-private.h > index 73108a0..80506be 100644 > --- a/pixman/pixman-private.h > +++ b/pixman/pixman-private.h > @@ -889,12 +889,12 @@ pixman_list_move_to_front (pixman_list_t *list, > pixman_link_t *link) > #endif > > /* Integer division that rounds towards -infinity */ > -#define DIV(a, b) \ > - ((((a) < 0) == ((b) < 0)) ? (a) / (b) : \ > - ((a) - (b) + 1 - (((b) < 0) << 1)) / (b)) > +#define DIV(a, b) \ > + ((a) / (b) - ((a) % (b) != 0 && ((a) % (b) < 0) != ((b) < 0) ? 1 : 0)) > > /* Modulus that produces the remainder wrt. DIV */ > -#define MOD(a, b) ((a) < 0 ? ((b) - ((-(a) - 1) % (b))) - 1 : (a) % (b)) > +#define MOD(a, b) \ > + ((a) % (b) + ((a) % (b) != 0 && ((a) % (b) < 0) != ((b) < 0) ? (b) : > 0)) > > #define CLIP(v, low, high) ((v) < (low) ? (low) : ((v) > (high) ? (high) > : (v))) > > -- > 1.7.5.4 > > _______________________________________________ > Pixman mailing list > Pixman@lists.freedesktop.org > http://lists.freedesktop.org/mailman/listinfo/pixman >
_______________________________________________ Pixman mailing list Pixman@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/pixman