Annotation of researchv10no/libmp/mult.c, revision 1.1.1.1

1.1       root        1: #include "mp.h"
                      2: #undef unfast
                      3: mult(a,b,c) mint *a,*b,*c;
                      4: {      mint x,y,z;
                      5:        int sign;
                      6:        sign = 1;
                      7:        x.val=a->val;
                      8:        y.val=b->val;
                      9:        z.len=0;
                     10:        if(a->len<0)
                     11:        {       x.len= -a->len;
                     12:                sign= -sign;
                     13:        }
                     14:        else    x.len=a->len;
                     15:        if(b->len<0)
                     16:        {       y.len= -b->len;
                     17:                sign= -sign;
                     18:        }
                     19:        else    y.len=b->len;
                     20:        if(x.len == 0 || y.len == 0)
                     21:                z.len = 0;
                     22:        else if(x.len<y.len) m_mult(&y,&x,&z);
                     23:        else m_mult(&x,&y,&z);
                     24:        xfree(c);
                     25:        if(sign<0) c->len= -z.len;
                     26:        else c->len=z.len;
                     27:        c->val=z.val;
                     28: }
                     29: #define S2 x=a->val[j];
                     30: #define S3 x=x*b->val[i-j];
                     31: #ifdef unfast
                     32: #define S4 tradd(&carry,&sum,x);
                     33: #else
                     34: #define S4 sum.xx += x; if(sum.yy.high & 0100000) {sum.yy.high &= 077777; carry++;}
                     35: #endif
                     36: #define S5 c->val[i]=sum.yy.low&077777;
                     37: #define S6 sum.xx=sum.xx>>15;
                     38: #define S7 sum.yy.high=carry;
                     39: m_mult(a,b,c)
                     40: register mint *a,*b,*c;
                     41: {      register long x;
                     42:        union {long xx; struct half yy;} sum;
                     43:        int carry;
                     44:        int i,j;
                     45:        c->val=xalloc(a->len+b->len,"m_mult");
                     46:        sum.xx=0;
                     47:        for(i=0;i<b->len;i++)
                     48:        {       carry=0;
                     49:                for(j=0;j<i+1;j++)
                     50:                {       S2
                     51:                        S3
                     52:                        S4
                     53:                }
                     54:                S5
                     55:                S6
                     56:                S7
                     57:        }
                     58:        for(;i<a->len;i++)
                     59:        {       carry=0;
                     60:                for(j=i-b->len+1;j<i+1;j++)
                     61:                {       S2
                     62:                        S3
                     63:                        S4
                     64:                }
                     65:                S5
                     66:                S6
                     67:                S7
                     68:        }
                     69:        for(;i<a->len+b->len;i++)
                     70:        {       carry=0;
                     71:                for(j=i-b->len+1;j<a->len;j++)
                     72:                {       S2
                     73:                        S3
                     74:                        S4
                     75:                }
                     76:                S5
                     77:                S6
                     78:                S7
                     79:        }
                     80:        if(i == 0 || c->val[i-1]!=0)
                     81:                c->len=a->len+b->len;
                     82:        else    c->len=a->len+b->len-1;
                     83:        return;
                     84: }
                     85: tradd(a,b,c)
                     86: long c;
                     87: int *a;
                     88: register union {long xx; struct half yy;} *b;
                     89: {
                     90:        b->xx += c;
                     91:        if(b->yy.high&0100000)
                     92:        {       b->yy.high= b->yy.high&077777;
                     93:                *a += 1;
                     94:        }
                     95:        return;
                     96: }

unix.superglobalmegacorp.com

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