Annotation of OpenXM_contrib2/asir2000/builtin/math.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/builtin/math.c,v 1.3 2000/08/22 05:03:59 noro Exp $
1.2 noro 49: */
1.1 noro 50: #include "ca.h"
51: #include <math.h>
52: #include "parse.h"
53:
54: void Pdsqrt(),Pdsin(),Pdcos(),Pdtan(),Pdasin(),Pdacos(),Pdatan(),Pdlog(),Pdexp();
55: void Pabs(),Pdfloor(),Pdceil(),Pdrint();
56:
57: struct ftab math_tab[] = {
58: {"dsqrt",Pdsqrt,1},
59: {"dabs",Pabs,1},
60: {"dsin",Pdsin,1},
61: {"dcos",Pdcos,1},
62: {"dtan",Pdtan,1},
63: {"dlog",Pdlog,1},
64: {"dexp",Pdexp,1},
65: {"dasin",Pdasin,1},
66: {"dacos",Pdacos,1},
67: {"datan",Pdatan,1},
68: {"dfloor",Pdfloor,1},
69: {"dceil",Pdceil,1},
70: {"drint",Pdrint,1},
71: {0,0,0},
72: };
73:
74: void Pabs(arg,rp)
75: NODE arg;
76: Real *rp;
77: {
78: double s;
79:
80: s = fabs(ToReal(ARG0(arg)));
81: MKReal(s,*rp);
82: }
83:
84: void Pdsqrt(arg,rp)
85: NODE arg;
86: Real *rp;
87: {
88: double s;
89:
90: s = sqrt(ToReal(ARG0(arg)));
91: MKReal(s,*rp);
92: }
93:
94: void Pdsin(arg,rp)
95: NODE arg;
96: Real *rp;
97: {
98: double s;
99:
100: s = sin(ToReal(ARG0(arg)));
101: MKReal(s,*rp);
102: }
103:
104: void Pdcos(arg,rp)
105: NODE arg;
106: Real *rp;
107: {
108: double s;
109:
110: s = cos(ToReal(ARG0(arg)));
111: MKReal(s,*rp);
112: }
113:
114: void Pdtan(arg,rp)
115: NODE arg;
116: Real *rp;
117: {
118: double s;
119:
120: s = tan(ToReal(ARG0(arg)));
121: MKReal(s,*rp);
122: }
123:
124: void Pdasin(arg,rp)
125: NODE arg;
126: Real *rp;
127: {
128: double s;
129:
130: s = asin(ToReal(ARG0(arg)));
131: MKReal(s,*rp);
132: }
133:
134: void Pdacos(arg,rp)
135: NODE arg;
136: Real *rp;
137: {
138: double s;
139:
140: s = acos(ToReal(ARG0(arg)));
141: MKReal(s,*rp);
142: }
143:
144: void Pdatan(arg,rp)
145: NODE arg;
146: Real *rp;
147: {
148: double s;
149:
150: s = atan(ToReal(ARG0(arg)));
151: MKReal(s,*rp);
152: }
153:
154: void Pdlog(arg,rp)
155: NODE arg;
156: Real *rp;
157: {
158: double s;
159:
160: s = log(ToReal(ARG0(arg)));
161: MKReal(s,*rp);
162: }
163:
164: void Pdexp(arg,rp)
165: NODE arg;
166: Real *rp;
167: {
168: double s;
169:
170: s = exp(ToReal(ARG0(arg)));
171: MKReal(s,*rp);
172: }
173:
174: void Pdfloor(arg,rp)
175: NODE arg;
176: Q *rp;
177: {
178: L a;
179: unsigned int au,al;
180: int sgn;
181: Q q;
182: double d;
183:
184: if ( !ARG0(arg) ) {
185: *rp = 0;
186: return;
187: }
188: d = floor(ToReal(ARG0(arg)));
189: if ( d < -9.223372036854775808e18 || d >= 9.223372036854775808e18 )
190: error("dfloor : OverFlow");
1.4 ! noro 191: if ( !d ) {
! 192: *rp = 0;
! 193: return;
! 194: }
1.1 noro 195: a = (L)d;
196: if ( a < 0 ) {
197: sgn = -1;
198: a = -a;
199: } else
200: sgn = 1;
201: #if defined(i386) || defined(__alpha) || defined(VISUAL)
202: au = ((unsigned int *)&a)[1];
203: al = ((unsigned int *)&a)[0];
204: #else
205: al = ((unsigned int *)&a)[1];
206: au = ((unsigned int *)&a)[0];
207: #endif
208: if ( au ) {
209: NEWQ(q); SGN(q) = sgn; NM(q)=NALLOC(2); DN(q)=0;
210: PL(NM(q))=2; BD(NM(q))[0]=al; BD(NM(q))[1] = au;
211: } else {
212: UTOQ(al,q); SGN(q) = sgn;
213: }
214: *rp = q;
215: }
216:
217: void Pdceil(arg,rp)
218: NODE arg;
219: Q *rp;
220: {
221: L a;
222: unsigned int au,al;
223: int sgn;
224: Q q;
225: double d;
226:
227: if ( !ARG0(arg) ) {
228: *rp = 0;
229: return;
230: }
231: d = ceil(ToReal(ARG0(arg)));
232: if ( d < -9.223372036854775808e18 || d >= 9.223372036854775808e18 )
233: error("dceil : OverFlow");
1.4 ! noro 234: if ( !d ) {
! 235: *rp = 0;
! 236: return;
! 237: }
1.1 noro 238: a = (L)d;
239: if ( a < 0 ) {
240: sgn = -1;
241: a = -a;
242: } else
243: sgn = 1;
244: #if defined(i386) || defined(__alpha) || defined(VISUAL)
245: au = ((unsigned int *)&a)[1];
246: al = ((unsigned int *)&a)[0];
247: #else
248: al = ((unsigned int *)&a)[1];
249: au = ((unsigned int *)&a)[0];
250: #endif
251: if ( au ) {
252: NEWQ(q); SGN(q) = sgn; NM(q)=NALLOC(2); DN(q)=0;
253: PL(NM(q))=2; BD(NM(q))[0]=al; BD(NM(q))[1] = au;
254: } else {
255: UTOQ(al,q); SGN(q) = sgn;
256: }
257: *rp = q;
258: }
259:
260: void Pdrint(arg,rp)
261: NODE arg;
262: Q *rp;
263: {
264: L a;
265: unsigned int au,al;
266: int sgn;
267: Q q;
268: double d;
269:
270: if ( !ARG0(arg) ) {
271: *rp = 0;
272: return;
273: }
274: #if defined(VISUAL)
275: d = ToReal(ARG0(arg));
276: if ( d > 0 )
277: d = floor(d+0.5);
278: else
279: d = ceil(d-0.5);
280: #else
281: d = rint(ToReal(ARG0(arg)));
282: #endif
283: if ( d < -9.223372036854775808e18 || d >= 9.223372036854775808e18 )
284: error("drint : OverFlow");
285: a = (L)d;
286: if ( a < 0 ) {
287: sgn = -1;
288: a = -a;
289: } else
290: sgn = 1;
291: #if defined(i386) || defined(__alpha) || defined(VISUAL)
292: au = ((unsigned int *)&a)[1];
293: al = ((unsigned int *)&a)[0];
294: #else
295: al = ((unsigned int *)&a)[1];
296: au = ((unsigned int *)&a)[0];
297: #endif
298: if ( au ) {
299: NEWQ(q); SGN(q) = sgn; NM(q)=NALLOC(2); DN(q)=0;
300: PL(NM(q))=2; BD(NM(q))[0]=al; BD(NM(q))[1] = au;
301: } else {
302: UTOQ(al,q); SGN(q) = sgn;
303: }
304: *rp = q;
305: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>