home *** CD-ROM | disk | FTP | other *** search
- plydiv(p,s,ndp,nds,q,r,ndq,ndr)
-
- /*this function divides two polynomials and retains the */
- /*remainder. Divisor, dividend, quotient, and remainder */
- /*are of the form a(1)*x**nda + a(2)*x**(nda-1) + ... */
- /*+ a(nda)*x + a(nda+1). */
-
- int ndp,nds,*ndq,*ndr;
- float p[],s[],q[],r[];
-
- {
- int nv,ntq,i,ip,j,js,k,kq,it,n,nq;
- float xx,zz;
- double fabs();
-
- nv = 0;
- /* if q[0]=999999. the function calculates only the remainder */
- if (q[0] == 999999.) nv = 1;
- *ndq = ndp - nds;
- ntq = *ndq ;
- j = ndp;
-
- for(ip = 0; ip<= j; ip++)
- r[ip] = p[ip];
- if(*ndq < 0) goto r1;
- ip = 0;
- js = 0;
- kq = 0;
- it = 0;
- q[kq] = p[ip]/s[js];
-
- r[ip] = p[ip] - s[js]*q[kq];
- while(js != (nds))
- {
- js = js + 1;
- ip = ip + 1;
- r[ip] = p[ip] - s[js]*q[kq];
- }
-
- a5: if(ntq <= kq) goto r2;
- kq = kq + 1;
- it = it + 1;
- ip = it;
- js = 0;
- if (r[ip] == 0.) goto a11;
- if (s[0] == 0.) goto a9;
- xx = r[ip]/s[0];
- a8: if(fabs(xx) <= 0.000005) goto a11;
- a9: nq = 0;
- if(nv != 1) nq = kq;
- q[nq] = r[ip]/s[js];
- a13: r[ip] = r[ip] - s[js]*q[nq];
- a14: if(js == (nds)) goto a5;
- js = js + 1;
- ip = ip + 1;
- goto a13;
- a11: if(nv != 1) q[kq] = 0.0;
- goto a5;
- r1: if(nv != 1) q[0] = 0.0;
- *ndq = 0;
- *ndr = ndp;
- return;
- r2: j = ndp;
- i = 0;
- a17: if (r[i] == 0.) goto a19;
- if (s[i] == 0.) goto a16;
- zz = r[i]/s[i];
- a18: if (fabs(zz) <= 0.000005) goto a19;
- a16: *ndr = j - i;
- n = *ndr;
- for(k = 0; k <= n; k++)
- {
- r[k] = r[i];
- i = i + 1;
- }
- return;
- a19: if(j <= i) goto r22;
- i = i + 1;
- goto a17;
- r22: *ndr = 0;
- r[0] = 0.0;
- return;
- }