1: #ifndef lint 2: static char sccs_id[] = "@(#)gcd.c 2.2 8/13/82"; 3: #endif lint 4: #include <ape.h> 5: gcd(a,b,c) 6: MINT *a,*b,*c; /* c = gcd of a and b; computed by 7: the Euclidean algorithm */ 8: { MINT x,y,z,w; 9: x.len=y.len=z.len=w.len=0; 10: 11: move(a,&x); 12: move(b,&y); 13: 14: while(y.len!=0) 15: { mdiv(&x,&y,&w,&z); 16: move(&y,&x); 17: move(&z,&y); 18: } 19: move(&x,c); 20: xfree(&x); 21: xfree(&y); 22: xfree(&z); 23: xfree(&w); 24: return; 25: } 26: 27: /* Until I know what this ought to do I'm leaving it out 28: 29: invert(a, b, c) 30: MINT *a, *b, *c; 31: { MINT x, y, z, w, Anew, Aold; 32: int i = 0; 33: x.len = y.len = z.len = w.len = Aold.len = 0; 34: Anew.len = 1; 35: Anew.val = xalloc(1,"invert"); 36: *Anew.val = 1; 37: move(b, &x); 38: move(a, &y); 39: while(y.len != 0) 40: { mdiv(&x, &y, &w, &z); 41: move(&Anew, &x); 42: mult(&w, &Anew, &Anew); 43: madd(&Anew, &Aold, &Anew); 44: move(&x, &Aold); 45: move(&y, &x); 46: move(&z, &y); 47: i++; 48: } 49: move(&Aold, c); 50: if( (i&01) == 0) msub(b, c, c); 51: xfree(&x); 52: xfree(&y); 53: xfree(&z); 54: xfree(&w); 55: xfree(&Aold); 56: xfree(&Anew); 57: } 58: I'm adding this, which is sort of an ``invert''! */ 59: 60: reciprocal(a,n,b) 61: PMINT a,b; /* b = 10^n / a -- i.e., gives n decimal places 62: * of 1/a. */ 63: int n; 64: { 65: PMINT x; 66: 67: new(&x); 68: lpow(10,(long)n,x); 69: mdiv(x,a,b,x); 70: afree(x); 71: return; 72: }