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

Defined functions

m_mult defined in line 47; used 2 times
tradd defined in line 95; used 1 times
  • in line 43

Defined variables

sccs_id defined in line 3; never used

Defined struct's

half defined in line 6; used 4 times
  • in line 50(2), 96(2)

Defined union's

g defined in line 96; never used

Defined macros

S2 defined in line 41; used 3 times
S3 defined in line 42; used 3 times
S4 defined in line 43; used 3 times
S5 defined in line 44; used 3 times
S6 defined in line 45; used 3 times
S7 defined in line 46; used 3 times
Last modified: 1983-07-23
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 944
Valid CSS Valid XHTML 1.0 Strict