diff options
author | Tor Andersson <tor@ghostscript.com> | 2004-09-27 02:15:04 +0200 |
---|---|---|
committer | Tor Andersson <tor@ghostscript.com> | 2004-09-27 02:15:04 +0200 |
commit | 6ddde92a3a45e970b05770633dc6a337d5d013c5 (patch) | |
tree | 1dec4612d7469839478e72d16d30a0da5755243c /include/fitz/math.h | |
download | mupdf-6ddde92a3a45e970b05770633dc6a337d5d013c5.tar.xz |
Initial import
Diffstat (limited to 'include/fitz/math.h')
-rw-r--r-- | include/fitz/math.h | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/include/fitz/math.h b/include/fitz/math.h new file mode 100644 index 00000000..acefeb50 --- /dev/null +++ b/include/fitz/math.h @@ -0,0 +1,30 @@ +/* multiply 8-bit fixpoint (0..1) so that 0*0==0 and 255*255==255 */ +static inline unsigned char fz_mul255(unsigned char a, unsigned char b) +{ + return ((a + 1) * b) >> 8; +} + +/* 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; +} + |