Commit | Line | Data |
---|---|---|
051b1e55 | 1 | #ifndef lint |
3bc5312c | 2 | static char sccsid[] = "@(#)gcd.c 5.3 (Berkeley) %G%"; |
051b1e55 | 3 | #endif not lint |
c3a0d10b SL |
4 | |
5 | #include <mp.h> | |
6 | gcd(a,b,c) MINT *a,*b,*c; | |
7 | { MINT x,y,z,w; | |
8 | x.len=y.len=z.len=w.len=0; | |
9 | move(a,&x); | |
10 | move(b,&y); | |
11 | while(y.len!=0) | |
12 | { mdiv(&x,&y,&w,&z); | |
13 | move(&y,&x); | |
14 | move(&z,&y); | |
15 | } | |
16 | move(&x,c); | |
17 | xfree(&x); | |
18 | xfree(&y); | |
19 | xfree(&z); | |
20 | xfree(&w); | |
21 | return; | |
22 | } | |
23 | invert(a, b, c) MINT *a, *b, *c; | |
24 | { MINT x, y, z, w, Anew, Aold; | |
25 | int i = 0; | |
26 | x.len = y.len = z.len = w.len = Aold.len = 0; | |
27 | Anew.len = 1; | |
39120317 | 28 | Anew.val = xalloc(1, "invert"); |
c3a0d10b SL |
29 | *Anew.val = 1; |
30 | move(b, &x); | |
31 | move(a, &y); | |
32 | while(y.len != 0) | |
33 | { mdiv(&x, &y, &w, &z); | |
34 | move(&Anew, &x); | |
35 | mult(&w, &Anew, &Anew); | |
36 | madd(&Anew, &Aold, &Anew); | |
37 | move(&x, &Aold); | |
38 | move(&y, &x); | |
39 | move(&z, &y); | |
40 | i++; | |
41 | } | |
42 | move(&Aold, c); | |
43 | if( (i&01) == 0) msub(b, c, c); | |
44 | xfree(&x); | |
45 | xfree(&y); | |
46 | xfree(&z); | |
47 | xfree(&w); | |
48 | xfree(&Aold); | |
49 | xfree(&Anew); | |
50 | } |