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

Annotation of OpenXM_contrib2/asir2018/engine/cplx.c, Revision 1.2

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:  *
1.2     ! noro       48:  * $OpenXM: OpenXM_contrib2/asir2018/engine/cplx.c,v 1.1 2018/09/19 05:45:07 noro Exp $
1.1       noro       49: */
                     50: #include "ca.h"
                     51: #include "base.h"
                     52:
                     53: void toreim(a,rp,ip)
                     54: Num a;
                     55: Num *rp,*ip;
                     56: {
                     57:   if ( !a )
                     58:     *rp = *ip = 0;
                     59: #if defined(INTERVAL)
                     60:   else if ( NID(a) <= N_PRE_C ) {
                     61: #else
                     62:   else if ( NID(a) <= N_B ) {
                     63: #endif
                     64:     *rp = a; *ip = 0;
                     65:   } else {
                     66:     *rp = ((C)a)->r; *ip = ((C)a)->i;
                     67:   }
                     68: }
                     69:
                     70: void reimtocplx(r,i,cp)
                     71: Num r,i;
                     72: Num *cp;
                     73: {
                     74:   C c;
                     75:
                     76:   if ( !i )
                     77:     *cp = r;
                     78:   else {
                     79:     NEWC(c); c->r = r; c->i = i; *cp = (Num)c;
                     80:   }
                     81: }
                     82:
                     83: void addcplx(a,b,c)
                     84: Num a,b;
                     85: Num *c;
                     86: {
                     87:   Num ar,ai,br,bi,cr,ci;
                     88:
                     89:   if ( !a )
                     90:     *c = b;
                     91:   else if ( !b )
                     92:     *c = a;
                     93: #if defined(INTERVAL)
                     94:   else if ( (NID(a) <= N_PRE_C) && (NID(b) <= N_PRE_C ) )
                     95: #else
                     96:   else if ( (NID(a) <= N_B) && (NID(b) <= N_B ) )
                     97: #endif
                     98:     addnum(0,a,b,c);
                     99:   else {
                    100:     toreim(a,&ar,&ai); toreim(b,&br,&bi);
                    101:     addnum(0,ar,br,&cr); addnum(0,ai,bi,&ci);
                    102:     reimtocplx(cr,ci,c);
                    103:   }
                    104: }
                    105:
                    106: void subcplx(a,b,c)
                    107: Num a,b;
                    108: Num *c;
                    109: {
                    110:   Num ar,ai,br,bi,cr,ci;
                    111:
                    112:   if ( !a )
                    113:     chsgnnum(b,c);
                    114:   else if ( !b )
                    115:     *c = a;
                    116: #if defined(INTERVAL)
                    117:   else if ( (NID(a) <= N_PRE_C) && (NID(b) <= N_PRE_C ) )
                    118: #else
                    119:   else if ( (NID(a) <= N_B) && (NID(b) <= N_B ) )
                    120: #endif
                    121:     subnum(0,a,b,c);
                    122:   else {
                    123:     toreim(a,&ar,&ai); toreim(b,&br,&bi);
                    124:     subnum(0,ar,br,&cr); subnum(0,ai,bi,&ci);
                    125:     reimtocplx(cr,ci,c);
                    126:   }
                    127: }
                    128:
                    129: void mulcplx(a,b,c)
                    130: Num a,b;
                    131: Num *c;
                    132: {
                    133:   Num ar,ai,br,bi,cr,ci,t,s;
                    134:
                    135:   if ( !a || !b )
                    136:     *c = 0;
                    137: #if defined(INTERVAL)
                    138:   else if ( (NID(a) <= N_PRE_C) && (NID(b) <= N_PRE_C ) )
                    139: #else
                    140:   else if ( (NID(a) <= N_B) && (NID(b) <= N_B ) )
                    141: #endif
                    142:     mulnum(0,a,b,c);
                    143:   else {
                    144:     toreim(a,&ar,&ai); toreim(b,&br,&bi);
                    145:     mulnum(0,ar,br,&t); mulnum(0,ai,bi,&s); subnum(0,t,s,&cr);
                    146:     mulnum(0,ar,bi,&t); mulnum(0,ai,br,&s); addnum(0,t,s,&ci);
                    147:     reimtocplx(cr,ci,c);
                    148:   }
                    149: }
                    150:
                    151: void divcplx(a,b,c)
                    152: Num a,b;
                    153: Num *c;
                    154: {
                    155:   Num ar,ai,br,bi,cr,ci,t,s,u,w;
                    156:
                    157:   if ( !b )
                    158:     error("divcplx : division by 0");
                    159:   else if ( !a )
                    160:     *c = 0;
                    161: #if defined(INTERVAL)
                    162:   else if ( (NID(a) <= N_PRE_C) && (NID(b) <= N_PRE_C ) )
                    163: #else
                    164:   else if ( (NID(a) <= N_B) && (NID(b) <= N_B ) )
                    165: #endif
                    166:     divnum(0,a,b,c);
                    167:   else {
                    168:     toreim(a,&ar,&ai); toreim(b,&br,&bi);
                    169:     mulnum(0,br,br,&t); mulnum(0,bi,bi,&s); addnum(0,t,s,&u);
                    170:     mulnum(0,ar,br,&t); mulnum(0,ai,bi,&s);
                    171:     addnum(0,t,s,&w); divnum(0,w,u,&cr);
                    172:     mulnum(0,ar,bi,&t); mulnum(0,ai,br,&s);
                    173:     subnum(0,s,t,&w); divnum(0,w,u,&ci);
                    174:     reimtocplx(cr,ci,c);
                    175:   }
                    176: }
                    177:
                    178: void pwrcplx(a,e,c)
                    179: Num a,e;
                    180: Num *c;
                    181: {
                    182:   int ei;
                    183:   Num t;
                    184:
                    185:   if ( !e )
                    186:     *c = (Num)ONE;
                    187:   else if ( !a )
                    188:     *c = 0;
                    189:   else if ( !INT(e) )
                    190:     error("pwrcplx : not implemented (use eval()).");
                    191:   else {
1.2     ! noro      192:     ei = sgnq((Q)e)*ZTOS((Q)e);
1.1       noro      193:     pwrcplx0(a,ei,&t);
                    194:     if ( sgnq((Q)e) < 0 )
                    195:       divnum(0,(Num)ONE,t,c);
                    196:     else
                    197:       *c = t;
                    198:   }
                    199: }
                    200:
                    201: void pwrcplx0(a,e,c)
                    202: Num a;
                    203: int e;
                    204: Num *c;
                    205: {
                    206:   Num t,s;
                    207:
                    208:   if ( e == 1 )
                    209:     *c = a;
                    210:   else {
                    211:     pwrcplx0(a,e/2,&t);
                    212:     if ( !(e%2) )
                    213:       mulnum(0,t,t,c);
                    214:     else {
                    215:       mulnum(0,t,t,&s); mulnum(0,s,a,c);
                    216:     }
                    217:   }
                    218: }
                    219:
                    220: void chsgncplx(a,c)
                    221: Num a,*c;
                    222: {
                    223:   Num r,i;
                    224:
                    225:   if ( !a )
                    226:     *c = 0;
                    227: #if defined(INTERVAL)
                    228:   else if ( NID(a) <= N_PRE_C )
                    229: #else
                    230:   else if ( NID(a) <= N_B )
                    231: #endif
                    232:     chsgnnum(a,c);
                    233:   else {
                    234:     chsgnnum(((C)a)->r,&r); chsgnnum(((C)a)->i,&i);
                    235:     reimtocplx(r,i,c);
                    236:   }
                    237: }
                    238:
                    239: int cmpcplx(a,b)
                    240: Num a,b;
                    241: {
                    242:   Num ar,ai,br,bi;
                    243:   int s;
                    244:
                    245:   if ( !a ) {
                    246: #if defined(INTERVAL)
                    247:     if ( !b || (NID(b)<=N_PRE_C) )
                    248: #else
                    249:     if ( !b || (NID(b)<=N_B) )
                    250: #endif
                    251:       return compnum(0,a,b);
                    252:     else
                    253:       return -1;
                    254:   } else if ( !b ) {
                    255: #if defined(INTERVAL)
                    256:     if ( !a || (NID(a)<=N_PRE_C) )
                    257: #else
                    258:     if ( !a || (NID(a)<=N_B) )
                    259: #endif
                    260:       return compnum(0,a,b);
                    261:     else
                    262:       return 1;
                    263:   } else {
                    264:     toreim(a,&ar,&ai); toreim(b,&br,&bi);
                    265:     s = compnum(0,ar,br);
                    266:     if ( s )
                    267:       return s;
                    268:     else
                    269:       return compnum(0,ai,bi);
                    270:   }
                    271: }

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