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