Annotation of OpenXM_contrib2/asir2000/engine-27/ddN-27.c, Revision 1.1
1.1 ! noro 1: /* $OpenXM: OpenXM/src/asir99/engine-27/ddN-27.c,v 1.1.1.1 1999/11/10 08:12:27 noro Exp $ */
! 2: #include "ca-27.h"
! 3: #include "base.h"
! 4: #include "inline.h"
! 5:
! 6: void divn_27(n1,n2,nq,nr)
! 7: N n1,n2,*nq,*nr;
! 8: {
! 9: int tmp;
! 10: int br;
! 11: int j,d,d1,d2,dd;
! 12: int *m1,*m1e,*m2,*mr;
! 13: N q,r;
! 14:
! 15: if ( !n2 )
! 16: error("divn: division by 0");
! 17: else if ( !n1 ) {
! 18: *nq = 0; *nr = 0;
! 19: } else if ( UNIN(n2) ) {
! 20: *nq = n1; *nr = 0;
! 21: } else if ( (d1 = PL(n1)) < (d2 = PL(n2)) ) {
! 22: *nr = n1; *nq = 0;
! 23: } else if ( d2 == 1 ) {
! 24: if ( d1 == 1 ) {
! 25: DQR(BD(n1)[0],BD(n2)[0],br,tmp)
! 26: STON(br,*nq); STON(tmp,*nr);
! 27: } else {
! 28: tmp = divin_27(n1,BD(n2)[0],nq); STON(tmp,*nr);
! 29: }
! 30: return;
! 31: } else if ( (d1 == d2) && ((tmp = cmpn(n1,n2)) <= 0) )
! 32: if ( !tmp ) {
! 33: *nr = 0; *nq = ONEN;
! 34: } else {
! 35: *nr = n1; *nq = 0;
! 36: }
! 37: else {
! 38: d = BASE27/(BD(n2)[d2-1] + 1); dd = d1-d2;
! 39: m1 = W_ALLOC(d1+1); m2 = W_ALLOC(d2+1);
! 40: mulin_27(n1,d,m1); mulin_27(n2,d,m2);
! 41: *nq = q = NALLOC(dd+1);
! 42: divnmain_27(d1,d2,m1,m2,BD(q));
! 43: PL(q) = (BD(q)[dd]?dd+1:dd);
! 44: for ( j = d2-1; (j >= 0) && (m1[j] == 0); j--);
! 45: if ( j == -1 )
! 46: *nr = 0;
! 47: else {
! 48: *nr = r = NALLOC(j+1);
! 49: for ( br = 0, m1e = m1+j, mr = BD(r)+j;
! 50: m1e >= m1; m1e--, mr-- ) {
! 51: DSAB27(d,br,*m1e,*mr,br)
! 52: }
! 53: PL(r) = (BD(r)[j]?j+1:j);
! 54: }
! 55: }
! 56: }
! 57:
! 58: void divnmain_27(d1,d2,m1,m2,q)
! 59: int d1,d2;
! 60: int *m1,*m2,*q;
! 61: {
! 62: unsigned int tmp;
! 63: int *n1,*n2;
! 64: int i,j;
! 65: int l,r;
! 66: int u,qhat;
! 67: int v1,v2;
! 68:
! 69: v1 = m2[d2-1]; v2 = m2[d2-2];
! 70: for ( j = d1-d2, m1 += j, q += j; j >= 0; j--, q--, m1-- ) {
! 71: n1 = m1+d2; n2 = m1+d2-1;
! 72: if ( *n1 == v1 ) {
! 73: qhat = BASE27 - 1; r = *n1 + *n2;
! 74: } else {
! 75: DSAB27(v1,*n1,*n2,qhat,r)
! 76: }
! 77: DM27(v2,qhat,u,l)
! 78: while ( 1 ) {
! 79: if ((r > u) || ((r == u) && (*(n1-2) >= l)))
! 80: break;
! 81: if ( ( l -= v2 ) < 0 ) {
! 82: l += BASE27; u--;
! 83: }
! 84: r += v1; qhat--;
! 85: }
! 86: if ( qhat ) {
! 87: for ( i = d2, u = 0, n1 = m1, n2 = m2; i > 0; i--, n1++, n2++ ) {
! 88: DMA27(*n2,qhat,u,u,l)
! 89: if ( (l = *n1 - l) < 0 ) {
! 90: u++; *n1 = l + BASE27;
! 91: } else
! 92: *n1 = l;
! 93: }
! 94: if ( *n1 < u ) {
! 95: for ( i = d2, qhat--, r = 0, n1 = m1, n2 = m2;
! 96: i > 0; i--, n1++, n2++ ) {
! 97: l = *n1 + *n2 + r; *n1 = l % BASE27; r = l / BASE27;
! 98: }
! 99: }
! 100: *n1 = 0;
! 101: }
! 102: *q = qhat;
! 103: }
! 104: }
! 105:
! 106: void mulin_27(n,d,p)
! 107: N n;
! 108: int d;
! 109: int *p;
! 110: {
! 111: int carry;
! 112: int *m,*me;
! 113:
! 114: bzero((char *)p,(int)((PL(n)+1)*sizeof(int)));
! 115: for ( carry = 0, m = BD(n), me = m+PL(n); m < me; p++, m++ ) {
! 116: carry += *p;
! 117: DMA27(*m,d,carry,carry,*p)
! 118: }
! 119: *p = carry;
! 120: }
! 121:
! 122: int divin_27(n,dvr,q)
! 123: N n;
! 124: int dvr;
! 125: N *q;
! 126: {
! 127: int up,d;
! 128: int *m,*mq,*md;
! 129: N nq;
! 130:
! 131: d = PL(n); m = BD(n);
! 132: if ( ( d == 1 ) && ( dvr > *m ) ) {
! 133: *q = 0;
! 134: return( *m );
! 135: }
! 136: *q = nq = NALLOC(d);
! 137: for ( md = m+d-1, mq = BD(nq)+d-1, up = 0; md >= m; md--, mq-- ) {
! 138: DSAB27(dvr,up,*md,*mq,up)
! 139: }
! 140: PL(nq) = (BD(nq)[d-1]?d:d-1);
! 141: return ( up );
! 142: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>