diff options
author | Tor Andersson <tor@ghostscript.com> | 2005-06-07 15:09:48 +0200 |
---|---|---|
committer | Tor Andersson <tor@ghostscript.com> | 2005-06-07 15:09:48 +0200 |
commit | cefd16bc7a557ccaf0bb66d504d7a8cbc9ec43d3 (patch) | |
tree | fbfc8e852b3fea2f355cee6016f9976f8304666e /include/fitz/base_math.h | |
parent | 5998b49add853664ad08f57071770b5433e667be (diff) | |
download | mupdf-cefd16bc7a557ccaf0bb66d504d7a8cbc9ec43d3.tar.xz |
more shuffling
Diffstat (limited to 'include/fitz/base_math.h')
-rw-r--r-- | include/fitz/base_math.h | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/include/fitz/base_math.h b/include/fitz/base_math.h new file mode 100644 index 00000000..4dee81fc --- /dev/null +++ b/include/fitz/base_math.h @@ -0,0 +1,29 @@ +/* multiply 8-bit fixpoint (0..1) so that 0*0==0 and 255*255==255 */ +#define fz_mul255(a,b) (((a) * ((b) + 1)) >> 8) +#define fz_floor(x) floor(x) +#define fz_ceil(x) ceil(x) + +/* divide and floor towards -inf */ +static inline int fz_idiv(int a, int b) +{ + return a < 0 ? (a - b + 1) / b : a / b; +} + +/* from python */ +static inline void fz_idivmod(int x, int y, int *d, int *m) +{ + int xdivy = x / y; + int xmody = x - xdivy * y; + /* If the signs of x and y differ, and the remainder is non-0, + * C89 doesn't define whether xdivy is now the floor or the + * ceiling of the infinitely precise quotient. We want the floor, + * and we have it iff the remainder's sign matches y's. + */ + if (xmody && ((y ^ xmody) < 0)) { + xmody += y; + xdivy --; + } + *d = xdivy; + *m = xmody; +} + |