1: #include "lint.h"
2: #ifndef lint
3: static char sccs_id[] = "%W% %G%";
4: #endif lint
5: #include <stdio.h>
6: #include <ape.h>
7: square(a,b) /* b = a^2, recursive version */
8: PMINT a,b;
9: {
10: MINT low, high, x, y;
11: int half;
12:
13: if (a->len == 0) { /* first base case -- a==0 */
14: xfree(b);
15: return;
16: }
17: half = a->len / 2;
18: if (half == 0) { /* second base case -- a->len == 1 */
19: long answer;
20:
21: answer = ( (long) a->val[0] ) * ( (long) a->val[0] );
22: makemint(b,answer);
23: return;
24: }
25: if (half < 0) half = -half;
26: low.len = half;
27: low.val = a->val;
28: high.len = a->len - half;
29: high.val = &(a->val[half]);
30: x.len = 0;
31: y.len = 0;
32:
33: square(&low,&x); /* (low+high)^2=low^2+high^2+2low*high */
34: square(&high,&y);
35: lshift(&y,half+half);
36: madd(&x,&y,&x);
37: mult(&low,&high,&y);
38: lshift(&y,half);
39: madd(&x,&y,&x);
40: madd(&x,&y,&x);
41: xfree(&y);
42: *b = x;
43: }
Defined functions
square
defined in line
7; used 3 times
Defined variables