[cairo] Transform+Repeat patch for libpixman

Carl Worth cworth at cworth.org
Tue Oct 12 08:21:22 PDT 2004


On Sun, 12 Sep 2004 05:13:57 +0200, David Reveman wrote:
> The patch looks good to me, one little problem though:
> 
> I changed
> #define mod(a,b)       ((b) == 1 ? 0 : (a) >= 0 ? (a) % (b) : (b) - (-a)
> % (b))
> to
> #define mod(a,b)       ((b) == 1 ? 0 : (a) >= 0 ? (a) % (b) : (a) % (b)
> == 0 ? 0: (b) + (a) % (b))

David,

Good catch. But in fixing one bug, you've inadvertently introduced
another.

Owen had:

	(b) - (-a) % (b)

which, from the point of view of mathmetical cleanliess, would be better
as your:

	(b) + (a) % (b)

The subtle snag here is that C (as of C89) yields implementation-defined
results for integer / and % with negative operands. So, we have to avoid
that. For the uses in pixman, we only have to worry about a, since b is
always positive, (either width or height).

With C99, integer / and % are well-defined. There, / rounds toward 0 and
% is defined such that, (assuming a/b is representable):

	(a/b)*b + a%b == a

Which means that even then, we have to do the fiddling to get the mod we
want. And it seems to me we should be able to come up with something a
bit tighter than what we have above.

Any suggestions?

Oh, and we have this macro defined twice in the code, (now with both
buggy versions above). We should reduce that to one working version.

-Carl



More information about the cairo mailing list