Debian Codegraph @

texk/dvipsk/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 #include "dvips.h" /* The copyright notice in that file is included too! */
17 /*
18 * The external declarations:
19 */
20 #include "protos.h"
21
22 integer
23 scalewidth(register integer a, register integer b)
24 {
25 register integer al, bl;
26
27 if (a < 0)
28 return -scalewidth(-a, b);
29 if (b < 0)
30 return -scalewidth(a, -b);
31 al = a & 32767;
32 bl = b & 32767;
33 a >>= 15;
34 b >>= 15;
35 return ( ((al*bl/32768) + a*bl+al*b)/32 + a*b*1024);
36 }