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

Annotation of OpenXM_contrib2/asir2000/parse/arith.c, Revision 1.2

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
        !            26:  * e-mail at risa-admin@flab.fujitsu.co.jp of the detailed specification
        !            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:  *
        !            48:  * $OpenXM: OpenXM_contrib2/asir2000/parse/arith.c,v 1.1.1.1 1999/12/03 07:39:11 noro Exp $
        !            49: */
1.1       noro       50: #include "ca.h"
                     51: #include "parse.h"
                     52:
                     53: struct oAFUNC {
                     54:        void (*add)();
                     55:        void (*sub)();
                     56:        void (*mul)();
                     57:        void (*div)();
                     58:        void (*pwr)();
                     59:        void (*chsgn)();
                     60:        int (*comp)();
                     61: };
                     62:
                     63: struct oARF arf[6];
                     64: ARF addfs, subfs, mulfs, divfs, remfs, pwrfs;
                     65:
                     66: void divsdc();
                     67:
                     68: struct oAFUNC afunc[] = {
                     69: /* ??? */      {0,0,0,0,0,0,0},
                     70: /* O_N */      {addnum,subnum,mulnum,divnum,pwrnum,chsgnnum,compnum},
                     71: /* O_P */      {addp,subp,mulp,divr,pwrp,chsgnp,compp},
                     72: /* O_R */      {addr,subr,mulr,divr,pwrr,chsgnr,compr},
                     73: /* O_LIST */   {notdef,notdef,notdef,notdef,notdef,notdef,complist},
                     74: /* O_VECT */   {addvect,subvect,mulvect,divvect,notdef,chsgnvect,compvect},
                     75: /* O_MAT */    {addmat,submat,mulmat,divmat,pwrmat,chsgnmat,compmat},
                     76: /* O_STR */    {addstr,notdef,notdef,notdef,notdef,notdef,compstr},
                     77: /* O_COMP */   {addcomp,subcomp,mulcomp,divcomp,pwrcomp,chsgncomp,compcomp},
                     78: /* O_DP */   {addd,subd,muld,divsdc,notdef,chsgnd,compd},
                     79: /* O_UI */     {notdef,notdef,notdef,notdef,notdef,notdef,compui},
                     80: /* O_GF2MAT */ {notdef,notdef,notdef,notdef,notdef,notdef,(int(*)())notdef},
                     81: /* O_ERR */    {notdef,notdef,notdef,notdef,notdef,notdef,(int(*)())notdef},
                     82: /* O_GFMMAT */ {notdef,notdef,notdef,notdef,notdef,notdef,(int(*)())notdef},
                     83: };
                     84:
                     85: void arf_init() {
                     86:        addfs = &arf[0]; addfs->name = "+"; addfs->fp = arf_add;
                     87:        subfs = &arf[1]; subfs->name = "-"; subfs->fp = arf_sub;
                     88:        mulfs = &arf[2]; mulfs->name = "*"; mulfs->fp = arf_mul;
                     89:        divfs = &arf[3]; divfs->name = "/"; divfs->fp = arf_div;
                     90:        remfs = &arf[4]; remfs->name = "%"; remfs->fp = arf_remain;
                     91:        pwrfs = &arf[5]; pwrfs->name = "^"; pwrfs->fp = arf_pwr;
                     92: }
                     93:
                     94: void arf_add(vl,a,b,r)
                     95: VL vl;
                     96: Obj a,b,*r;
                     97: {
                     98:        int mid;
                     99:
                    100:        if ( !a )
                    101:                *r = b;
                    102:        else if ( !b )
                    103:                *r = a;
                    104:        else if ( OID(a) == OID(b) )
                    105:                (*afunc[OID(a)].add)(vl,a,b,r);
                    106:        else if ( (mid = MAX(OID(a),OID(b))) <= O_R )
                    107:                (*afunc[mid].add)(vl,a,b,r);
                    108:        else
                    109:                notdef(vl,a,b,r);
                    110: }
                    111:
                    112: void arf_sub(vl,a,b,r)
                    113: VL vl;
                    114: Obj a,b,*r;
                    115: {
                    116:        int mid;
                    117:
                    118:        if ( !a )
                    119:                if ( !b )
                    120:                        *r = 0;
                    121:                else
                    122:                        (*afunc[OID(b)].chsgn)(b,r);
                    123:        else if ( !b )
                    124:                *r = a;
                    125:        else if ( OID(a) == OID(b) )
                    126:                (*afunc[OID(a)].sub)(vl,a,b,r);
                    127:        else if ( (mid = MAX(OID(a),OID(b))) <= O_R )
                    128:                (*afunc[mid].sub)(vl,a,b,r);
                    129:        else
                    130:                notdef(vl,a,b,r);
                    131: }
                    132:
                    133: void arf_mul(vl,a,b,r)
                    134: VL vl;
                    135: Obj a,b,*r;
                    136: {
                    137:        int mid;
                    138:
                    139:        if ( !a || !b )
                    140:                *r = 0;
                    141:        else if ( OID(a) == OID(b) )
                    142:                (*(afunc[OID(a)].mul))(vl,a,b,r);
                    143:        else if ( (mid = MAX(OID(a),OID(b))) <= O_R ||
                    144:                (mid == O_MAT) || (mid == O_VECT) || (mid == O_DP) )
                    145:                (*afunc[mid].mul)(vl,a,b,r);
                    146:        else
                    147:                notdef(vl,a,b,r);
                    148: }
                    149:
                    150: void arf_div(vl,a,b,r)
                    151: VL vl;
                    152: Obj a,b,*r;
                    153: {
                    154:        int mid;
                    155:
                    156:        if ( !b )
                    157:                error("div : division by 0");
                    158:        if ( !a )
                    159:                *r = 0;
                    160:        else if ( (OID(a) == OID(b)) )
                    161:                (*(afunc[OID(a)].div))(vl,a,b,r);
                    162:        else if ( (mid = MAX(OID(a),OID(b))) <= O_R ||
                    163:                (mid == O_MAT) || (mid == O_VECT) || (mid == O_DP) )
                    164:                (*afunc[mid].div)(vl,a,b,r);
                    165:        else
                    166:                notdef(vl,a,b,r);
                    167: }
                    168:
                    169: void arf_remain(vl,a,b,r)
                    170: VL vl;
                    171: Obj a,b,*r;
                    172: {
                    173:        if ( !b )
                    174:                error("rem : division by 0");
                    175:        else if ( !a )
                    176:                *r = 0;
                    177:        else if ( MAX(OID(a),OID(b)) <= O_P )
                    178:                cmp((Q)b,(P)a,(P *)r);
                    179:        else
                    180:                notdef(vl,a,b,r);
                    181: }
                    182:
                    183: void arf_pwr(vl,a,e,r)
                    184: VL vl;
                    185: Obj a,e,*r;
                    186: {
                    187:        R t;
                    188:
                    189:        if ( !a )
                    190:                *r = 0;
                    191:        else if ( !e )
                    192:                *r = (pointer)ONE;
                    193:        else if ( (OID(e) <= O_N) && INT(e) ) {
                    194:                if ( (OID(a) == O_P) && (SGN((Q)e) < 0) ) {
                    195:                        MKRAT((P)a,(P)ONE,1,t);
                    196:                        (*(afunc[O_R].pwr))(vl,t,e,r);
                    197:                } else
                    198:                        (*(afunc[OID(a)].pwr))(vl,a,e,r);
                    199:        } else if ( OID(a) <= O_R )
                    200:                mkpow(vl,a,e,r);
                    201:        else
                    202:                notdef(vl,a,e,r);
                    203: }
                    204:
                    205: void arf_chsgn(a,r)
                    206: Obj a,*r;
                    207: {
                    208:        if ( !a )
                    209:                *r = 0;
                    210:        else
                    211:                (*(afunc[OID(a)].chsgn))(a,r);
                    212: }
                    213:
                    214: int arf_comp(vl,a,b)
                    215: VL vl;
                    216: Obj a,b;
                    217: {
                    218:        if ( !a )
                    219:                if ( !b )
                    220:                        return 0;
                    221:                else
                    222:                        return (*afunc[OID(b)].comp)(vl,a,b);
                    223:        else if ( !b )
                    224:                        return (*afunc[OID(a)].comp)(vl,a,b);
                    225:        else if ( OID(a) != OID(b) )
                    226:                return OID(a)>OID(b) ? 1 : -1;
                    227:        else
                    228:                return (*afunc[OID(a)].comp)(vl,a,b);
                    229: }
                    230:
                    231: int complist(vl,a,b)
                    232: VL vl;
                    233: LIST a,b;
                    234: {
                    235:        int i,t;
                    236:        NODE an,bn;
                    237:
                    238:        if ( !a )
                    239:                if ( !b )
                    240:                        return 0;
                    241:                else
                    242:                        return -1;
                    243:        else if ( !b )
                    244:                return 1;
                    245:        for ( i = 0, an = BDY(a); an; i++, an = NEXT(an) );
                    246:        for ( an = BDY(b); an; i--, an = NEXT(an) );
                    247:        if ( i )
                    248:                return i > 0 ? 1 : -1;
                    249:        for ( an = BDY(a), bn = BDY(b); an; an = NEXT(an), bn = NEXT(bn) )
                    250:                if ( t = arf_comp(vl,BDY(an),BDY(bn)) )
                    251:                        return t;
                    252:        return 0;
                    253: }

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