[BACK]Return to C.c CVS log [TXT][DIR] Up to [local] / OpenXM_contrib2 / asir2000 / engine

Annotation of OpenXM_contrib2/asir2000/engine/C.c, Revision 1.5

1.2       noro        1: /*
                      2:  * Copyright (c) 1994-2000 FUJITSU LABORATORIES LIMITED
                      3:  * All rights reserved.
                      4:  *
                      5:  * FUJITSU LABORATORIES LIMITED ("FLL") hereby grants you a limited,
                      6:  * non-exclusive and royalty-free license to use, copy, modify and
                      7:  * redistribute, solely for non-commercial and non-profit purposes, the
                      8:  * computer program, "Risa/Asir" ("SOFTWARE"), subject to the terms and
                      9:  * conditions of this Agreement. For the avoidance of doubt, you acquire
                     10:  * only a limited right to use the SOFTWARE hereunder, and FLL or any
                     11:  * third party developer retains all rights, including but not limited to
                     12:  * copyrights, in and to the SOFTWARE.
                     13:  *
                     14:  * (1) FLL does not grant you a license in any way for commercial
                     15:  * purposes. You may use the SOFTWARE only for non-commercial and
                     16:  * non-profit purposes only, such as academic, research and internal
                     17:  * business use.
                     18:  * (2) The SOFTWARE is protected by the Copyright Law of Japan and
                     19:  * international copyright treaties. If you make copies of the SOFTWARE,
                     20:  * with or without modification, as permitted hereunder, you shall affix
                     21:  * to all such copies of the SOFTWARE the above copyright notice.
                     22:  * (3) An explicit reference to this SOFTWARE and its copyright owner
                     23:  * shall be made on your publication or presentation in any form of the
                     24:  * results obtained by use of the SOFTWARE.
                     25:  * (4) In the event that you modify the SOFTWARE, you shall notify FLL by
1.3       noro       26:  * e-mail at risa-admin@sec.flab.fujitsu.co.jp of the detailed specification
1.2       noro       27:  * for such modification or the source code of the modified part of the
                     28:  * SOFTWARE.
                     29:  *
                     30:  * THE SOFTWARE IS PROVIDED AS IS WITHOUT ANY WARRANTY OF ANY KIND. FLL
                     31:  * MAKES ABSOLUTELY NO WARRANTIES, EXPRESSED, IMPLIED OR STATUTORY, AND
                     32:  * EXPRESSLY DISCLAIMS ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS
                     33:  * FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT OF THIRD PARTIES'
                     34:  * RIGHTS. NO FLL DEALER, AGENT, EMPLOYEES IS AUTHORIZED TO MAKE ANY
                     35:  * MODIFICATIONS, EXTENSIONS, OR ADDITIONS TO THIS WARRANTY.
                     36:  * UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, TORT, CONTRACT,
                     37:  * OR OTHERWISE, SHALL FLL BE LIABLE TO YOU OR ANY OTHER PERSON FOR ANY
                     38:  * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, PUNITIVE OR CONSEQUENTIAL
                     39:  * DAMAGES OF ANY CHARACTER, INCLUDING, WITHOUT LIMITATION, DAMAGES
                     40:  * ARISING OUT OF OR RELATING TO THE SOFTWARE OR THIS AGREEMENT, DAMAGES
                     41:  * FOR LOSS OF GOODWILL, WORK STOPPAGE, OR LOSS OF DATA, OR FOR ANY
                     42:  * DAMAGES, EVEN IF FLL SHALL HAVE BEEN INFORMED OF THE POSSIBILITY OF
                     43:  * SUCH DAMAGES, OR FOR ANY CLAIM BY ANY OTHER PARTY. EVEN IF A PART
                     44:  * OF THE SOFTWARE HAS BEEN DEVELOPED BY A THIRD PARTY, THE THIRD PARTY
                     45:  * DEVELOPER SHALL HAVE NO LIABILITY IN CONNECTION WITH THE USE,
                     46:  * PERFORMANCE OR NON-PERFORMANCE OF THE SOFTWARE.
                     47:  *
1.5     ! noro       48:  * $OpenXM: OpenXM_contrib2/asir2000/engine/C.c,v 1.4 2001/03/13 01:10:25 noro Exp $
1.2       noro       49: */
1.1       noro       50: #include "ca.h"
                     51: #include "inline.h"
                     52: #include "base.h"
                     53:
                     54: V up_var;
                     55:
                     56: /* binary has at least 32 leading 0 chars. */
                     57: void binaryton(binary,np)
                     58: char *binary;
                     59: N *np;
                     60: {
                     61:        int i,w,len;
                     62:        N n;
                     63:        char buf[33];
                     64:
                     65:        binary += strlen(binary)%32;
                     66:        len = strlen(binary);
                     67:        w = len/32; /* sufficient for holding binary */
                     68:        n = NALLOC(w);
                     69:        for ( i = 0; i < w; i++ ) {
                     70:                strncpy(buf,binary+len-32*(i+1),32); buf[32] = 0;
                     71:                n->b[i] = strtoul(buf,0,2);
                     72:        }
                     73:        for ( i = w-1; i >= 0 && !n->b[i]; i-- );
                     74:        if ( i < 0 )
                     75:                *np = 0;
                     76:        else {
                     77:                n->p = i+1;
                     78:                *np = n;
                     79:        }
                     80: }
                     81:
                     82: /* hex has at least 8 leading 0 chars. */
                     83: void hexton(hex,np)
                     84: char *hex;
                     85: N *np;
                     86: {
                     87:        int i,w,len;
                     88:        N n;
                     89:        char buf[9];
                     90:
                     91:        hex += strlen(hex)%8;
                     92:        len = strlen(hex);
                     93:        w = len/8; /* sufficient for holding hex */
                     94:        n = NALLOC(w);
                     95:        for ( i = 0; i < w; i++ ) {
                     96:                strncpy(buf,hex+len-8*(i+1),8); buf[8] = 0;
                     97:                n->b[i] = strtoul(buf,0,16);
                     98:        }
                     99:        for ( i = w-1; i >= 0 && !n->b[i]; i-- );
                    100:        if ( i < 0 )
                    101:                *np = 0;
                    102:        else {
                    103:                n->p = i+1;
                    104:                *np = n;
                    105:        }
                    106: }
                    107:
                    108: void ntobn(base,n,nrp)
                    109: int base;
                    110: N n,*nrp;
                    111: {
                    112:        int i,d,plc;
                    113:        unsigned int *c,*x,*w;
                    114:        unsigned int r;
                    115:        L m;
                    116:        N nr;
                    117:
                    118:        if ( !n ) {
                    119:                *nrp = NULL;
                    120:                return;
                    121:        }
                    122:
                    123:        d = PL(n);
                    124:        w = BD(n);
                    125:
                    126:        for ( i = 1, m = 1; m <= LBASE/(L)base; m *= base, i++ );
                    127:
                    128:        c = (unsigned int *)W_ALLOC(d*i+1);
                    129:        x = (unsigned int *)W_ALLOC(d+1);
                    130:        for ( i = 0; i < d; i++ )
                    131:                x[i] = w[i];
                    132:        for ( plc = 0; d >= 1; plc++ ) {
                    133:                for ( i = d - 1, r = 0; i >= 0; i-- ) {
                    134:                        DSAB((unsigned int)base,r,x[i],x[i],r)
                    135:                }
                    136:                c[plc] = r;
                    137:                if ( !x[d-1] ) d--;
                    138:        }
                    139:
                    140:        *nrp = nr = NALLOC(plc); INITRC(nr);
                    141:        PL(nr) = plc;
                    142:        for ( i = 0; i < plc; i++ )
                    143:                BD(nr)[i] = c[i];
                    144: }
                    145:
                    146: void bnton(base,n,nrp)
                    147: int base;
                    148: N n,*nrp;
                    149: {
                    150:        unsigned int carry;
                    151:        unsigned int *x,*w;
                    152:        int i,j,d,plc;
                    153:        N nr;
                    154:
                    155:        if ( !n ) {
                    156:                *nrp = 0;
                    157:                return;
                    158:        }
                    159:
                    160:        d = PL(n);
                    161:        w = BD(n);
                    162:        x = (unsigned int *)W_ALLOC(d + 1);
                    163:
                    164:        for ( plc = 0, i = d - 1; i >= 0; i-- ) {
                    165:                for ( carry = w[i],j = 0; j < plc; j++ ) {
                    166:                        DMA(x[j],(unsigned int)base,carry,carry,x[j])
                    167:                }
                    168:                if ( carry ) x[plc++] = carry;
                    169:        }
                    170:        *nrp = nr = NALLOC(plc); INITRC(nr);
                    171:        PL(nr) = plc;
                    172:        for ( i = 0; i < plc; i++ )
                    173:                BD(nr)[i] = x[i];
                    174: }
                    175:
                    176: void ptomp(m,p,pr)
                    177: int m;
                    178: P p;
                    179: P *pr;
                    180: {
                    181:        DCP dc,dcr,dcr0;
                    182:        Q q;
                    183:        unsigned int a,b;
                    184:        P t;
                    185:        MQ s;
                    186:
                    187:        if ( !p )
                    188:                *pr = 0;
                    189:        else if ( NUM(p) ) {
                    190:                q = (Q)p;
                    191:                a = rem(NM(q),m);
                    192:                if ( a && (SGN(q) < 0) )
                    193:                        a = m-a;
                    194:                b = !DN(q)?1:rem(DN(q),m);
                    195:                if ( !b )
                    196:                        error("ptomp : denominator = 0");
                    197:                a = dmar(a,invm(b,m),0,m); STOMQ(a,s); *pr = (P)s;
                    198:        } else {
                    199:                for ( dc = DC(p), dcr0 = 0; dc; dc = NEXT(dc) ) {
                    200:                        ptomp(m,COEF(dc),&t);
                    201:                        if ( t ) {
                    202:                                NEXTDC(dcr0,dcr); DEG(dcr) = DEG(dc); COEF(dcr) = t;
                    203:                        }
                    204:                }
                    205:                if ( !dcr0 )
                    206:                        *pr = 0;
                    207:                else {
                    208:                        NEXT(dcr) = 0; MKP(VR(p),dcr0,*pr);
                    209:                }
                    210:        }
                    211: }
                    212:
                    213: void mptop(f,gp)
                    214: P f;
                    215: P *gp;
                    216: {
                    217:        DCP dc,dcr,dcr0;
                    218:        Q q;
                    219:
                    220:        if ( !f )
                    221:                *gp = 0;
                    222:        else if ( NUM(f) )
                    223:                STOQ(CONT((MQ)f),q),*gp = (P)q;
                    224:        else {
                    225:                for ( dc = DC(f), dcr0 = 0; dc; dc = NEXT(dc) ) {
                    226:                        NEXTDC(dcr0,dcr); DEG(dcr) = DEG(dc); mptop(COEF(dc),&COEF(dcr));
1.4       noro      227:                }
                    228:                NEXT(dcr) = 0; MKP(VR(f),dcr0,*gp);
                    229:        }
                    230: }
                    231:
                    232: void sfptop(f,gp)
                    233: P f;
                    234: P *gp;
                    235: {
                    236:        DCP dc,dcr,dcr0;
                    237:        Q q;
1.5     ! noro      238:        MQ fq;
1.4       noro      239:
                    240:        if ( !f )
                    241:                *gp = 0;
                    242:        else if ( NUM(f) ) {
1.5     ! noro      243:                gfstomq((GFS)f,&fq);
        !           244:                STOQ(CONT(fq),q);
        !           245:                *gp = (P)q;
1.4       noro      246:        } else {
                    247:                for ( dc = DC(f), dcr0 = 0; dc; dc = NEXT(dc) ) {
                    248:                        NEXTDC(dcr0,dcr); DEG(dcr) = DEG(dc); sfptop(COEF(dc),&COEF(dcr));
1.1       noro      249:                }
                    250:                NEXT(dcr) = 0; MKP(VR(f),dcr0,*gp);
                    251:        }
                    252: }
                    253:
                    254: void ptolmp(p,pr)
                    255: P p;
                    256: P *pr;
                    257: {
                    258:        DCP dc,dcr,dcr0;
                    259:        LM a;
                    260:        P t;
                    261:
                    262:        if ( !p )
                    263:                *pr = 0;
                    264:        else if ( NUM(p) ) {
                    265:                qtolm((Q)p,&a); *pr = (P)a;
                    266:        } else {
                    267:                for ( dc = DC(p), dcr0 = 0; dc; dc = NEXT(dc) ) {
                    268:                        ptolmp(COEF(dc),&t);
                    269:                        if ( t ) {
                    270:                                NEXTDC(dcr0,dcr); DEG(dcr) = DEG(dc); COEF(dcr) = t;
                    271:                        }
                    272:                }
                    273:                if ( !dcr0 )
                    274:                        *pr = 0;
                    275:                else {
                    276:                        NEXT(dcr) = 0; MKP(VR(p),dcr0,*pr);
                    277:                }
                    278:        }
                    279: }
                    280:
                    281: void lmptop(f,gp)
                    282: P f;
                    283: P *gp;
                    284: {
                    285:        DCP dc,dcr,dcr0;
                    286:        Q q;
                    287:
                    288:        if ( !f )
                    289:                *gp = 0;
                    290:        else if ( NUM(f) ) {
                    291:                NTOQ(((LM)f)->body,1,q); *gp = (P)q;
                    292:        } else {
                    293:                for ( dc = DC(f), dcr0 = 0; dc; dc = NEXT(dc) ) {
                    294:                        NEXTDC(dcr0,dcr); DEG(dcr) = DEG(dc); lmptop(COEF(dc),&COEF(dcr));
                    295:                }
                    296:                NEXT(dcr) = 0; MKP(VR(f),dcr0,*gp);
                    297:        }
                    298: }
                    299:
                    300: void ptoum(m,f,wf)
                    301: int m;
                    302: P f;
                    303: UM wf;
                    304: {
                    305:        unsigned int r;
                    306:        int i;
                    307:        DCP dc;
                    308:
                    309:        for ( i = UDEG(f); i >= 0; i-- )
                    310:                COEF(wf)[i] = 0;
                    311:
                    312:        for ( dc = DC(f); dc; dc = NEXT(dc) ) {
                    313:                r = rem(NM((Q)COEF(dc)),m);
                    314:                if ( r && (SGN((Q)COEF(dc)) < 0) )
                    315:                        r = m-r;
                    316:                COEF(wf)[QTOS(DEG(dc))] = r;
                    317:        }
                    318:        degum(wf,UDEG(f));
                    319: }
                    320:
                    321: void umtop(v,w,f)
                    322: V v;
                    323: UM w;
                    324: P *f;
                    325: {
                    326:        int *c;
                    327:        DCP dc,dc0;
                    328:        int i;
                    329:        Q q;
                    330:
                    331:        if ( DEG(w) < 0 )
                    332:                *f = 0;
                    333:        else if ( DEG(w) == 0 )
                    334:                STOQ(COEF(w)[0],q), *f = (P)q;
                    335:        else {
                    336:                for ( i = DEG(w), c = COEF(w), dc0 = 0; i >= 0; i-- )
                    337:                        if ( c[i] ) {
                    338:                                NEXTDC(dc0,dc);
                    339:                                STOQ(i,DEG(dc));
                    340:                                STOQ(c[i],q), COEF(dc) = (P)q;
                    341:                        }
                    342:                NEXT(dc) = 0;
                    343:                MKP(v,dc0,*f);
                    344:        }
                    345: }
                    346:
                    347: void ptoup(n,nr)
                    348: P n;
                    349: UP *nr;
                    350: {
                    351:        DCP dc;
                    352:        UP r;
                    353:        int d;
                    354:
                    355:        if ( !n )
                    356:                *nr = 0;
                    357:        else if ( OID(n) == O_N ) {
                    358:                *nr = r = UPALLOC(0);
                    359:                DEG(r) = 0; COEF(r)[0] = (Num)n;
                    360:        } else {
                    361:                d = UDEG(n);
                    362:                up_var = VR(n);
                    363:                *nr = r = UPALLOC(d); DEG(r) = d;
                    364:                for ( dc = DC(n); dc; dc = NEXT(dc) ) {
                    365:                        COEF(r)[QTOS(DEG(dc))] = (Num)COEF(dc);
                    366:                }
                    367:        }
                    368: }
                    369:
                    370: void uptop(n,nr)
                    371: UP n;
                    372: P *nr;
                    373: {
                    374:        int i;
                    375:        DCP dc0,dc;
                    376:
                    377:        if ( !n )
                    378:                *nr = 0;
                    379:        else if ( !DEG(n) )
                    380:                *nr = (P)COEF(n)[0];
                    381:        else {
                    382:                for ( i = DEG(n), dc0 = 0; i >= 0; i-- )
                    383:                        if ( COEF(n)[i] ) {
                    384:                                NEXTDC(dc0,dc); STOQ(i,DEG(dc)); COEF(dc) = (P)COEF(n)[i];
                    385:                        }
                    386:                if ( !up_var )
                    387:                        up_var = CO->v;
                    388:                MKP(up_var,dc0,*nr);
                    389:        }
                    390: }
                    391:
                    392: void ulmptoum(m,f,wf)
                    393: int m;
                    394: UP f;
                    395: UM wf;
                    396: {
                    397:        int i,d;
                    398:        LM *c;
                    399:
                    400:        if ( !f )
                    401:                wf->d = -1;
                    402:        else {
                    403:                wf->d = d = f->d;
                    404:                c = (LM *)f->c;
                    405:                for ( i = 0, d = f->d; i <= d; i++ )
                    406:                        COEF(wf)[i] = rem(c[i]->body,m);
                    407:        }
                    408: }
                    409:
                    410: void objtobobj(base,p,rp)
                    411: int base;
                    412: Obj p;
                    413: Obj *rp;
                    414: {
                    415:        if ( !p )
                    416:                *rp = 0;
                    417:        else
                    418:                switch ( OID(p) ) {
                    419:                        case O_N:
                    420:                                numtobnum(base,(Num)p,(Num *)rp); break;
                    421:                        case O_P:
                    422:                                ptobp(base,(P)p,(P *)rp); break;
                    423:                        case O_LIST:
                    424:                                listtoblist(base,(LIST)p,(LIST *)rp); break;
                    425:                        case O_VECT:
                    426:                                vecttobvect(base,(VECT)p,(VECT *)rp); break;
                    427:                        case O_MAT:
                    428:                                mattobmat(base,(MAT)p,(MAT *)rp); break;
                    429:                        case O_STR:
                    430:                                *rp = p; break;
                    431:                        case O_COMP: default:
                    432:                                error("objtobobj : not implemented"); break;
                    433:                }
                    434: }
                    435:
                    436: void bobjtoobj(base,p,rp)
                    437: int base;
                    438: Obj p;
                    439: Obj *rp;
                    440: {
                    441:        if ( !p )
                    442:                *rp = 0;
                    443:        else
                    444:                switch ( OID(p) ) {
                    445:                        case O_N:
                    446:                                bnumtonum(base,(Num)p,(Num *)rp); break;
                    447:                        case O_P:
                    448:                                bptop(base,(P)p,(P *)rp); break;
                    449:                        case O_LIST:
                    450:                                blisttolist(base,(LIST)p,(LIST *)rp); break;
                    451:                        case O_VECT:
                    452:                                bvecttovect(base,(VECT)p,(VECT *)rp); break;
                    453:                        case O_MAT:
                    454:                                bmattomat(base,(MAT)p,(MAT *)rp); break;
                    455:                        case O_STR:
                    456:                                *rp = p; break;
                    457:                        case O_COMP: default:
                    458:                                error("bobjtoobj : not implemented"); break;
                    459:                }
                    460: }
                    461:
                    462: void numtobnum(base,p,rp)
                    463: int base;
                    464: Num p;
                    465: Num *rp;
                    466: {
                    467:        N nm,dn,body;
                    468:        Q q;
                    469:        LM l;
                    470:
                    471:        if ( !p )
                    472:                *rp = 0;
                    473:        else
                    474:                switch ( NID(p) ) {
                    475:                        case N_Q:
                    476:                                ntobn(base,NM((Q)p),&nm);
                    477:                                if ( DN((Q)p) ) {
                    478:                                        ntobn(base,DN((Q)p),&dn);
                    479:                                        NDTOQ(nm,dn,SGN((Q)p),q);
                    480:                                } else
                    481:                                        NTOQ(nm,SGN((Q)p),q);
                    482:                                *rp = (Num)q;
                    483:                                break;
                    484:                        case N_R:
                    485:                                *rp = p; break;
                    486:                        case N_LM:
                    487:                                ntobn(base,((LM)p)->body,&body);
                    488:                                MKLM(body,l); *rp = (Num)l;
                    489:                                break;
                    490:                        default:
                    491:                                error("numtobnum : not implemented"); break;
                    492:                }
                    493: }
                    494:
                    495: void bnumtonum(base,p,rp)
                    496: int base;
                    497: Num p;
                    498: Num *rp;
                    499: {
                    500:        N nm,dn,body;
                    501:        Q q;
                    502:        LM l;
                    503:
                    504:        if ( !p )
                    505:                *rp = 0;
                    506:        else
                    507:                switch ( NID(p) ) {
                    508:                        case N_Q:
                    509:                                bnton(base,NM((Q)p),&nm);
                    510:                                if ( DN((Q)p) ) {
                    511:                                        bnton(base,DN((Q)p),&dn);
                    512:                                        NDTOQ(nm,dn,SGN((Q)p),q);
                    513:                                } else
                    514:                                        NTOQ(nm,SGN((Q)p),q);
                    515:                                *rp = (Num)q;
                    516:                                break;
                    517:                        case N_R:
                    518:                                *rp = p; break;
                    519:                        case N_LM:
                    520:                                bnton(base,((LM)p)->body,&body);
                    521:                                MKLM(body,l); *rp = (Num)l;
                    522:                                break;
                    523:                        default:
                    524:                                error("bnumtonum : not implemented"); break;
                    525:                }
                    526: }
                    527:
                    528: void ptobp(base,p,rp)
                    529: int base;
                    530: P p;
                    531: P *rp;
                    532: {
                    533:        DCP dcr0,dcr,dc;
                    534:
                    535:        if ( !p )
                    536:                *rp = p;
                    537:        else {
                    538:                for ( dcr0 = 0, dc = DC(p); dc; dc = NEXT(dc) ) {
                    539:                        NEXTDC(dcr0,dcr); DEG(dcr) = DEG(dc);
                    540:                        objtobobj(base,(Obj)COEF(dc),(Obj *)&COEF(dcr));
                    541:                }
                    542:                NEXT(dcr) = 0;
                    543:                MKP(VR(p),dcr0,*rp);
                    544:        }
                    545: }
                    546:
                    547: void bptop(base,p,rp)
                    548: int base;
                    549: P p;
                    550: P *rp;
                    551: {
                    552:        DCP dcr0,dcr,dc;
                    553:
                    554:        if ( !p )
                    555:                *rp = p;
                    556:        else {
                    557:                for ( dcr0 = 0, dc = DC(p); dc; dc = NEXT(dc) ) {
                    558:                        NEXTDC(dcr0,dcr); DEG(dcr) = DEG(dc);
                    559:                        bobjtoobj(base,(Obj)COEF(dc),(Obj *)&COEF(dcr));
                    560:                }
                    561:                NEXT(dcr) = 0;
                    562:                MKP(VR(p),dcr0,*rp);
                    563:        }
                    564: }
                    565:
                    566: void listtoblist(base,p,rp)
                    567: int base;
                    568: LIST p;
                    569: LIST *rp;
                    570: {
                    571:        NODE nr0,nr,n;
                    572:
                    573:        if ( !p )
                    574:                *rp = p;
                    575:        else {
                    576:                for ( nr0 = 0, n = BDY(p); n; n = NEXT(n) ) {
                    577:                        NEXTNODE(nr0,nr);
                    578:                        objtobobj(base,BDY(n),(Obj *)&BDY(nr));
                    579:                }
                    580:                NEXT(nr) = 0;
                    581:                MKLIST(*rp,nr0);
                    582:        }
                    583: }
                    584:
                    585: void blisttolist(base,p,rp)
                    586: int base;
                    587: LIST p;
                    588: LIST *rp;
                    589: {
                    590:        NODE nr0,nr,n;
                    591:
                    592:        if ( !p )
                    593:                *rp = p;
                    594:        else {
                    595:                for ( nr0 = 0, n = BDY(p); n; n = NEXT(n) ) {
                    596:                        NEXTNODE(nr0,nr);
                    597:                        bobjtoobj(base,BDY(n),(Obj *)&BDY(nr));
                    598:                }
                    599:                NEXT(nr) = 0;
                    600:                MKLIST(*rp,nr0);
                    601:        }
                    602: }
                    603:
                    604: void vecttobvect(base,p,rp)
                    605: int base;
                    606: VECT p;
                    607: VECT *rp;
                    608: {
                    609:        int i,l;
                    610:        VECT r;
                    611:
                    612:        if ( !p )
                    613:                *rp = p;
                    614:        else {
                    615:                l = p->len;
                    616:                MKVECT(r,l); *rp = r;
                    617:                for ( i = 0; i < l; i++ )
                    618:                        objtobobj(base,p->body[i],(Obj *)&r->body[i]);
                    619:        }
                    620: }
                    621:
                    622: void bvecttovect(base,p,rp)
                    623: int base;
                    624: VECT p;
                    625: VECT *rp;
                    626: {
                    627:        int i,l;
                    628:        VECT r;
                    629:
                    630:        if ( !p )
                    631:                *rp = p;
                    632:        else {
                    633:                l = p->len;
                    634:                MKVECT(r,l); *rp = r;
                    635:                for ( i = 0; i < l; i++ )
                    636:                        bobjtoobj(base,p->body[i],(Obj *)&r->body[i]);
                    637:        }
                    638: }
                    639:
                    640: void mattobmat(base,p,rp)
                    641: int base;
                    642: MAT p;
                    643: MAT *rp;
                    644: {
                    645:        int row,col,i,j;
                    646:        MAT r;
                    647:
                    648:        if ( !p )
                    649:                *rp = p;
                    650:        else {
                    651:                row = p->row; col = p->col;
                    652:                MKMAT(r,row,col); *rp = r;
                    653:                for ( i = 0; i < row; i++ )
                    654:                        for ( j = 0; i < col; j++ )
                    655:                        objtobobj(base,p->body[i][j],(Obj *)&r->body[i][j]);
                    656:        }
                    657: }
                    658:
                    659: void bmattomat(base,p,rp)
                    660: int base;
                    661: MAT p;
                    662: MAT *rp;
                    663: {
                    664:        int row,col,i,j;
                    665:        MAT r;
                    666:
                    667:        if ( !p )
                    668:                *rp = p;
                    669:        else {
                    670:                row = p->row; col = p->col;
                    671:                MKMAT(r,row,col); *rp = r;
                    672:                for ( i = 0; i < row; i++ )
                    673:                        for ( j = 0; i < col; j++ )
                    674:                        bobjtoobj(base,p->body[i][j],(Obj *)&r->body[i][j]);
                    675:        }
                    676: }
                    677:
                    678: void n32ton27(g,rp)
                    679: N g;
                    680: N *rp;
                    681: {
                    682:        int i,j,k,l,r,bits,words;
                    683:        unsigned int t;
                    684:        unsigned int *a,*b;
                    685:        N z;
                    686:
                    687:        l = PL(g); a = BD(g);
                    688:        for ( i = 31, t = a[l-1]; !(t&(1<<i)); i-- );
                    689:        bits = (l-1)*32+i+1; words = (bits+26)/27;
                    690:        *rp = z = NALLOC(words); PL(z) = words;
                    691:        bzero((char *)BD(z),words*sizeof(unsigned int));
                    692:        for ( j = 0, b = BD(z); j < words; j++ ) {
                    693:                k = (27*j)/32; r = (27*j)%32;
                    694:                if ( r > 5 )
                    695:                        b[j] = (a[k]>>r)|(k==(l-1)?0:((a[k+1]&((1<<(r-5))-1))<<(32-r)));
                    696:                else
                    697:                        b[j] = (a[k]>>r)&((1<<27)-1);
                    698:        }
                    699:        if ( !(r = bits%27) )
                    700:                r = 27;
                    701:        b[words-1] &= ((1<<r)-1);
                    702: }
                    703:
                    704: void n27ton32(a,rp)
                    705: N a;
                    706: N *rp;
                    707: {
                    708:        int i,j,k,l,r,bits,words;
                    709:        unsigned int t;
                    710:        unsigned int *b,*c;
                    711:        N z;
                    712:
                    713:        l = PL(a); b = BD(a);
                    714:        for ( i = 26, t = b[l-1]; !(t&(1<<i)); i-- );
                    715:        bits = (l-1)*27+i+1; words = (bits+31)/32;
                    716:        *rp = z = NALLOC(words); PL(z) = words;
                    717:        bzero((char *)BD(z),words*sizeof(unsigned int));
                    718:        for ( j = 0, c = BD(z); j < l; j++ ) {
                    719:                k = (27*j)/32; r = (27*j)%32;
                    720:                if ( r > 5 ) {
                    721:                        c[k] |= (b[j]&((1<<(32-r))-1))<<r;
                    722:                        if ( k+1 < words )
                    723:                                c[k+1] = (b[j]>>(32-r));
                    724:                } else
                    725:                        c[k] |= (b[j]<<r);
                    726:        }
                    727: }
                    728:
                    729: void mptoum(p,pr)
                    730: P p;
                    731: UM pr;
                    732: {
                    733:        DCP dc;
                    734:
                    735:        if ( !p )
                    736:                DEG(pr) = -1;
                    737:        else if ( NUM(p) ) {
                    738:                DEG(pr) = 0; COEF(pr)[0] = CONT((MQ)p);
                    739:        } else {
                    740:                bzero((char *)pr,(int)((UDEG(p)+2)*sizeof(int)));
                    741:                for ( dc = DC(p); dc; dc = NEXT(dc) )
                    742:                        COEF(pr)[QTOS(DEG(dc))] = CONT((MQ)COEF(dc));
                    743:                degum(pr,UDEG(p));
                    744:        }
                    745: }
                    746:
                    747: void umtomp(v,p,pr)
                    748: V v;
                    749: UM p;
                    750: P *pr;
                    751: {
                    752:        DCP dc,dc0;
                    753:        int i;
                    754:        MQ q;
                    755:
                    756:        if ( !p || (DEG(p) < 0) )
                    757:                *pr = 0;
                    758:        else if ( !DEG(p) )
                    759:                STOMQ(COEF(p)[0],q), *pr = (P)q;
                    760:        else {
                    761:                for ( dc0 = 0, i = DEG(p); i >= 0; i-- )
                    762:                        if ( COEF(p)[i] ) {
                    763:                                NEXTDC(dc0,dc); STOQ(i,DEG(dc));
                    764:                                STOMQ(COEF(p)[i],q), COEF(dc) = (P)q;
                    765:                        }
                    766:                NEXT(dc) = 0; MKP(v,dc0,*pr);
                    767:        }
                    768: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>