Annotation of 41BSD/lib/libmp/pow.c, revision 1.1

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

unix.superglobalmegacorp.com

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