Debian Codegraph @

texk/xdvipsk/scalewidth.c

raw
1 /*
2 * Code to scale dimensions. Takes two thirty-two bit integers, multiplies
3 * them, divides them by 2^20, and returns the thirty-two bit result.
4 * The first integer, the width in FIXes, can lie between -2^24 and 2^24-1.
5 * The second integer, the scale factor, can lie between 0 and 2^27-1.
6 *
7 * Here, unlike in TeX, we do the arithmetic exactly. Since the error
8 * in the TeX arithmetic is parts per million, and since dvips makes no
9 * layout decisions, this has no effect. (TeX stipulates that any
10 * implementation of *TeX* needs to do the arithmetic exactly as
11 * specified in TeX, but drivers need not.)
12 *
13 * Since this math is special, we put it in its own file. It is the only
14 * place in the program where such accuracy is required.
15 */
16 #ifndef XDVIPSK
17 #include "dvips.h" /* The copyright notice in that file is included too! */
18 #else
19 #include "xdvips.h" /* The copyright notice in that file is included too! */
20 #endif /* XDVIPSK */
21 /*
22 * The external declarations:
23 */
24 #include "protos.h"
25
26 integer
27 scalewidth(register integer a, register integer b)
28 {
29 register integer al, bl;
30
31 if (a < 0)
32 return -scalewidth(-a, b);
33 if (b < 0)
34 return -scalewidth(a, -b);
35 al = a & 32767;
36 bl = b & 32767;
37 a >>= 15;
38 b >>= 15;
39 return ( ((al*bl/32768) + a*bl+al*b)/32 + a*b*1024);
40 }