File: scale.c

package info (click to toggle)
vftool 2.0alpha-4%2Bsqueeze1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 388 kB
  • ctags: 769
  • sloc: ansic: 2,748; makefile: 190; sh: 79
file content (45 lines) | stat: -rw-r--r-- 818 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#define	LOWP	16
#define	FIXP	20
#define	LOWMASK	((1<<LOWP)-1)
#define	D	(1<<(FIXP-LOWP))
#define	H	(1<<(2*LOWP-FIXP))
#define	TPT(x, y)	((x)<<(y))	/* x * 2^y */
#define	DPT(x, y)	((x)>>(y))	/* x / 2^y */

scalesp(s, d)
int s, d;
{
    int sign;
    unsigned int s1, s0, d1, d0;

    sign = 1;
    if (s < 0) {
	sign = -1;
	s *= -1;
    }
    s0 = s & LOWMASK;
    d0 = d & LOWMASK;
    s1 = s >> LOWP;
    d1 = d >> LOWP;
    return (sign *
	    (TPT(s1*d1, 2*LOWP-FIXP) +
	     DPT(s1*d0+s0*d1 + DPT(s0*d0, LOWP), FIXP-LOWP))
	    );
}

/* very stupid routine that computes x/y */
divsp(x, y)
int x, y;
{
    int x0, x1, z0;

    z0 = (int)(((float)x/(float)y)*(1<<FIXP)) - 5;
    x0 = scalesp(y, z0);
    x1 = scalesp(y, z0+1);
    for (; x1 < x;) {
	z0++;
	x0 = x1;
	x1 = scalesp(y, z0+1);
    }
    return z0+1;
}