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