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

Annotation of OpenXM_contrib2/asir2018/engine/R.c, Revision 1.1

1.1     ! 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@sec.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$
        !            49: */
        !            50: #include "ca.h"
        !            51:
        !            52: void addr(VL vl,Obj a,Obj b,Obj *c)
        !            53: {
        !            54:   P t,s,u;
        !            55:   R r;
        !            56:
        !            57:   if ( !a )
        !            58:     *c = b;
        !            59:   else if ( !b )
        !            60:     *c = a;
        !            61:   else if ( !RAT(a) )
        !            62:     if ( !RAT(b) )
        !            63:       addp(vl,(P)a,(P)b,(P *)c);
        !            64:     else {
        !            65:       mulp(vl,(P)a,DN((R)b),&t); addp(vl,t,NM((R)b),&s);
        !            66:       if ( s )
        !            67:         MKRAT(s,DN((R)b),((R)b)->reduced,r);
        !            68:       else
        !            69:         r = 0;
        !            70:       *c = (Obj)r;
        !            71:     }
        !            72:   else if ( !RAT(b) ) {
        !            73:     mulp(vl,DN((R)a),(P)b,&t); addp(vl,NM((R)a),t,&s);
        !            74:     if ( s )
        !            75:       MKRAT(s,DN((R)a),((R)a)->reduced,r);
        !            76:     else
        !            77:       r = 0;
        !            78:     *c = (Obj)r;
        !            79:   } else {
        !            80:     mulp(vl,NM((R)a),DN((R)b),&t); mulp(vl,NM((R)b),DN((R)a),&s);
        !            81:     addp(vl,t,s,&u);
        !            82:     if ( u ) {
        !            83:       mulp(vl,DN((R)a),DN((R)b),&t); MKRAT(u,t,0,r); *c = (Obj)r;
        !            84:     } else
        !            85:       *c = 0;
        !            86:   }
        !            87: }
        !            88:
        !            89: void subr(VL vl,Obj a,Obj b,Obj *c)
        !            90: {
        !            91:   P t,s,u;
        !            92:   R r;
        !            93:
        !            94:   if ( !a )
        !            95:     chsgnr(b,c);
        !            96:   else if ( !b )
        !            97:     *c = a;
        !            98:   else if ( !RAT(a) )
        !            99:     if ( !RAT(b) )
        !           100:       subp(vl,(P)a,(P)b,(P *)c);
        !           101:     else {
        !           102:       mulp(vl,(P)a,DN((R)b),&t); subp(vl,t,NM((R)b),&s);
        !           103:       if ( s )
        !           104:         MKRAT(s,DN((R)b),((R)b)->reduced,r);
        !           105:       else
        !           106:         r = 0;
        !           107:       *c = (Obj)r;
        !           108:     }
        !           109:   else if ( !RAT(b) ) {
        !           110:     mulp(vl,DN((R)a),(P)b,&t); subp(vl,NM((R)a),t,&s);
        !           111:     if ( s )
        !           112:       MKRAT(s,DN((R)a),((R)a)->reduced,r);
        !           113:     else
        !           114:       r = 0;
        !           115:     *c = (Obj)r;
        !           116:   } else {
        !           117:     mulp(vl,NM((R)a),DN((R)b),&t); mulp(vl,NM((R)b),DN((R)a),&s);
        !           118:     subp(vl,t,s,&u);
        !           119:     if ( u ) {
        !           120:       mulp(vl,DN((R)a),DN((R)b),&t); MKRAT(u,t,0,r); *c = (Obj)r;
        !           121:     } else
        !           122:       *c = 0;
        !           123:   }
        !           124: }
        !           125:
        !           126: void mulr(VL vl,Obj a,Obj b,Obj *c)
        !           127: {
        !           128:   P t,s;
        !           129:   R r;
        !           130:
        !           131:   if ( !a || !b )
        !           132:     *c = 0;
        !           133:   else if ( !RAT(a) )
        !           134:     if ( !RAT(b) )
        !           135:       mulp(vl,(P)a,(P)b,(P *)c);
        !           136:     else {
        !           137:       mulp(vl,(P)a,NM((R)b),&t); MKRAT(t,DN((R)b),0,r); *c = (Obj)r;
        !           138:     }
        !           139:   else if ( !RAT(b) ) {
        !           140:     mulp(vl,NM((R)a),(P)b,&t); MKRAT(t,DN((R)a),0,r); *c = (Obj)r;
        !           141:   } else {
        !           142:     mulp(vl,NM((R)a),NM((R)b),&t); mulp(vl,DN((R)a),DN((R)b),&s);
        !           143:     MKRAT(t,s,0,r); *c = (Obj)r;
        !           144:   }
        !           145: }
        !           146:
        !           147: void divr(VL vl,Obj a,Obj b,Obj *c)
        !           148: {
        !           149:   P t,s;
        !           150:   R r;
        !           151:
        !           152:   if ( !b )
        !           153:     error("divr : division by 0");
        !           154:   else if ( !a )
        !           155:     *c = 0;
        !           156:   else if ( !RAT(a) )
        !           157:     if ( !RAT(b) )
        !           158:       if ( NUM(b) )
        !           159:         divsp(vl,(P)a,(P)b,(P *)c);
        !           160:       else {
        !           161:         MKRAT((P)a,(P)b,0,r); *c = (Obj)r;
        !           162:       }
        !           163:     else {
        !           164:       mulp(vl,(P)a,DN((R)b),&t); MKRAT(t,NM((R)b),0,r); *c = (Obj)r;
        !           165:     }
        !           166:   else if ( !RAT(b) ) {
        !           167:     mulp(vl,DN((R)a),(P)b,&t); MKRAT(NM((R)a),t,0,r); *c = (Obj)r;
        !           168:   } else {
        !           169:     mulp(vl,NM((R)a),DN((R)b),&t); mulp(vl,DN((R)a),NM((R)b),&s);
        !           170:     MKRAT(t,s,0,r); *c = (Obj)r;
        !           171:   }
        !           172: }
        !           173:
        !           174: void pwrr(VL vl,Obj a,Obj q,Obj *c)
        !           175: {
        !           176:   P t,s;
        !           177:   R r;
        !           178:   Z q1;
        !           179:
        !           180:   if ( !q )
        !           181:     *c = (Obj)ONE;
        !           182:   else if ( !a )
        !           183:     *c = 0;
        !           184:   else if ( !NUM(q) || !RATN(q) || !INT(q) )
        !           185:     notdef(vl,a,q,c);
        !           186:   else if ( !RAT(a) && (sgnq((Q)q) > 0) ) {
        !           187:       pwrp(vl,(P)a,(Z)q,&t); *c = (Obj)t;
        !           188:   } else {
        !           189:     if ( !RAT(a) ) {
        !           190:       PTOR((P)a,r); a = (Obj)r;
        !           191:     }
        !           192:     if ( sgnz((Z)q) < 0 ) {
        !           193:       chsgnz((Z)q,&q1); pwrp(vl,DN((R)a),q1,&t); pwrp(vl,NM((R)a),q1,&s);
        !           194:     } else {
        !           195:       pwrp(vl,NM((R)a),(Z)q,&t); pwrp(vl,DN((R)a),(Z)q,&s);
        !           196:     }
        !           197:     MKRAT(t,s,((R)a)->reduced,r); *c = (Obj)r;
        !           198:   }
        !           199: }
        !           200:
        !           201: void chsgnr(Obj a,Obj *b)
        !           202: {
        !           203:   P t;
        !           204:   R r;
        !           205:
        !           206:   if ( !a )
        !           207:     *b = 0;
        !           208:   else if ( !RAT(a) )
        !           209:     chsgnp((P)a,(P *)b);
        !           210:   else {
        !           211:     chsgnp(NM((R)a),&t); MKRAT(t,DN((R)a),((R)a)->reduced,r); *b = (Obj)r;
        !           212:   }
        !           213: }
        !           214:
        !           215: int compr(VL vl,Obj a,Obj b)
        !           216: {
        !           217:   int t;
        !           218:
        !           219:   if ( !a )
        !           220:     return b ? -1 : 0;
        !           221:   else if ( !b )
        !           222:     return 1;
        !           223:   else if ( !RAT(a) )
        !           224:     return !RAT(b) ? compp(vl,(P)a,(P)b) : -1;
        !           225:   else if ( !RAT(b) )
        !           226:     return 1;
        !           227:   else {
        !           228:     t = compp(vl,NM((R)a),NM((R)b));
        !           229:     if ( !t )
        !           230:       t = compp(vl,DN((R)a),DN((R)b));
        !           231:     return t;
        !           232:   }
        !           233: }
        !           234:
        !           235: int equalr(VL vl,Obj a,Obj b)
        !           236: {
        !           237:   if ( !a )
        !           238:     return b ? 0 : 1;
        !           239:   else if ( !b )
        !           240:     return 0;
        !           241:   else if ( !RAT(a) )
        !           242:     return !RAT(b) ? equalp(vl,(P)a,(P)b) : 0;
        !           243:   else if ( !RAT(b) )
        !           244:     return 0;
        !           245:   else
        !           246:     return equalp(vl,NM((R)a),NM((R)b)) && equalp(vl,DN((R)a),DN((R)b));
        !           247: }

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