Annotation of 42BSD/usr.lib/libmp/pow.c, revision 1.1.1.1

1.1       root        1: /*     @(#)pow.c       4.1     12/25/82        */
                      2: 
                      3: #include <mp.h>
                      4: pow(a,b,c,d) MINT *a,*b,*c,*d;
                      5: {      int i,j,n;
                      6:        MINT x,y;
                      7:        x.len=y.len=0;
                      8:        xfree(d);
                      9:        d->len=1;
                     10:        d->val=xalloc(1,"pow");
                     11:        *d->val=1;
                     12:        for(j=0;j<b->len;j++)
                     13:        {       n=b->val[b->len-j-1];
                     14:                for(i=0;i<15;i++)
                     15:                {       mult(d,d,&x);
                     16:                        mdiv(&x,c,&y,d);
                     17:                        if((n=n<<1)&0100000)
                     18:                        {       mult(a,d,&x);
                     19:                                mdiv(&x,c,&y,d);
                     20:                        }
                     21:                }
                     22:        }
                     23:        xfree(&x);
                     24:        xfree(&y);
                     25:        return;
                     26: }
                     27: rpow(a,n,b) MINT *a,*b;
                     28: {      MINT x,y;
                     29:        int i;
                     30:        x.len=1;
                     31:        x.val=xalloc(1,"rpow");
                     32:        *x.val=n;
                     33:        y.len=n*a->len+4;
                     34:        y.val=xalloc(y.len,"rpow2");
                     35:        for(i=0;i<y.len;i++) y.val[i]=0;
                     36:        y.val[y.len-1]=010000;
                     37:        xfree(b);
                     38:        pow(a,&x,&y,b);
                     39:        xfree(&x);
                     40:        xfree(&y);
                     41:        return;
                     42: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.