Annotation of OpenXM_contrib2/asir2000/builtin/math.c, Revision 1.1.1.1
1.1 noro 1: /* $OpenXM: OpenXM/src/asir99/builtin/math.c,v 1.1.1.1 1999/11/10 08:12:25 noro Exp $ */
2: #include "ca.h"
3: #include <math.h>
4: #include "parse.h"
5:
6: void Pdsqrt(),Pdsin(),Pdcos(),Pdtan(),Pdasin(),Pdacos(),Pdatan(),Pdlog(),Pdexp();
7: void Pabs(),Pdfloor(),Pdceil(),Pdrint();
8:
9: struct ftab math_tab[] = {
10: {"dsqrt",Pdsqrt,1},
11: {"dabs",Pabs,1},
12: {"dsin",Pdsin,1},
13: {"dcos",Pdcos,1},
14: {"dtan",Pdtan,1},
15: {"dlog",Pdlog,1},
16: {"dexp",Pdexp,1},
17: {"dasin",Pdasin,1},
18: {"dacos",Pdacos,1},
19: {"datan",Pdatan,1},
20: {"dfloor",Pdfloor,1},
21: {"dceil",Pdceil,1},
22: {"drint",Pdrint,1},
23: {0,0,0},
24: };
25:
26: void Pabs(arg,rp)
27: NODE arg;
28: Real *rp;
29: {
30: double s;
31:
32: s = fabs(ToReal(ARG0(arg)));
33: MKReal(s,*rp);
34: }
35:
36: void Pdsqrt(arg,rp)
37: NODE arg;
38: Real *rp;
39: {
40: double s;
41:
42: s = sqrt(ToReal(ARG0(arg)));
43: MKReal(s,*rp);
44: }
45:
46: void Pdsin(arg,rp)
47: NODE arg;
48: Real *rp;
49: {
50: double s;
51:
52: s = sin(ToReal(ARG0(arg)));
53: MKReal(s,*rp);
54: }
55:
56: void Pdcos(arg,rp)
57: NODE arg;
58: Real *rp;
59: {
60: double s;
61:
62: s = cos(ToReal(ARG0(arg)));
63: MKReal(s,*rp);
64: }
65:
66: void Pdtan(arg,rp)
67: NODE arg;
68: Real *rp;
69: {
70: double s;
71:
72: s = tan(ToReal(ARG0(arg)));
73: MKReal(s,*rp);
74: }
75:
76: void Pdasin(arg,rp)
77: NODE arg;
78: Real *rp;
79: {
80: double s;
81:
82: s = asin(ToReal(ARG0(arg)));
83: MKReal(s,*rp);
84: }
85:
86: void Pdacos(arg,rp)
87: NODE arg;
88: Real *rp;
89: {
90: double s;
91:
92: s = acos(ToReal(ARG0(arg)));
93: MKReal(s,*rp);
94: }
95:
96: void Pdatan(arg,rp)
97: NODE arg;
98: Real *rp;
99: {
100: double s;
101:
102: s = atan(ToReal(ARG0(arg)));
103: MKReal(s,*rp);
104: }
105:
106: void Pdlog(arg,rp)
107: NODE arg;
108: Real *rp;
109: {
110: double s;
111:
112: s = log(ToReal(ARG0(arg)));
113: MKReal(s,*rp);
114: }
115:
116: void Pdexp(arg,rp)
117: NODE arg;
118: Real *rp;
119: {
120: double s;
121:
122: s = exp(ToReal(ARG0(arg)));
123: MKReal(s,*rp);
124: }
125:
126: void Pdfloor(arg,rp)
127: NODE arg;
128: Q *rp;
129: {
130: L a;
131: unsigned int au,al;
132: int sgn;
133: Q q;
134: double d;
135:
136: if ( !ARG0(arg) ) {
137: *rp = 0;
138: return;
139: }
140: d = floor(ToReal(ARG0(arg)));
141: if ( d < -9.223372036854775808e18 || d >= 9.223372036854775808e18 )
142: error("dfloor : OverFlow");
143: a = (L)d;
144: if ( a < 0 ) {
145: sgn = -1;
146: a = -a;
147: } else
148: sgn = 1;
149: #if defined(i386) || defined(__alpha) || defined(VISUAL)
150: au = ((unsigned int *)&a)[1];
151: al = ((unsigned int *)&a)[0];
152: #else
153: al = ((unsigned int *)&a)[1];
154: au = ((unsigned int *)&a)[0];
155: #endif
156: if ( au ) {
157: NEWQ(q); SGN(q) = sgn; NM(q)=NALLOC(2); DN(q)=0;
158: PL(NM(q))=2; BD(NM(q))[0]=al; BD(NM(q))[1] = au;
159: } else {
160: UTOQ(al,q); SGN(q) = sgn;
161: }
162: *rp = q;
163: }
164:
165: void Pdceil(arg,rp)
166: NODE arg;
167: Q *rp;
168: {
169: L a;
170: unsigned int au,al;
171: int sgn;
172: Q q;
173: double d;
174:
175: if ( !ARG0(arg) ) {
176: *rp = 0;
177: return;
178: }
179: d = ceil(ToReal(ARG0(arg)));
180: if ( d < -9.223372036854775808e18 || d >= 9.223372036854775808e18 )
181: error("dceil : OverFlow");
182: a = (L)d;
183: if ( a < 0 ) {
184: sgn = -1;
185: a = -a;
186: } else
187: sgn = 1;
188: #if defined(i386) || defined(__alpha) || defined(VISUAL)
189: au = ((unsigned int *)&a)[1];
190: al = ((unsigned int *)&a)[0];
191: #else
192: al = ((unsigned int *)&a)[1];
193: au = ((unsigned int *)&a)[0];
194: #endif
195: if ( au ) {
196: NEWQ(q); SGN(q) = sgn; NM(q)=NALLOC(2); DN(q)=0;
197: PL(NM(q))=2; BD(NM(q))[0]=al; BD(NM(q))[1] = au;
198: } else {
199: UTOQ(al,q); SGN(q) = sgn;
200: }
201: *rp = q;
202: }
203:
204: void Pdrint(arg,rp)
205: NODE arg;
206: Q *rp;
207: {
208: L a;
209: unsigned int au,al;
210: int sgn;
211: Q q;
212: double d;
213:
214: if ( !ARG0(arg) ) {
215: *rp = 0;
216: return;
217: }
218: #if defined(VISUAL)
219: d = ToReal(ARG0(arg));
220: if ( d > 0 )
221: d = floor(d+0.5);
222: else
223: d = ceil(d-0.5);
224: #else
225: d = rint(ToReal(ARG0(arg)));
226: #endif
227: if ( d < -9.223372036854775808e18 || d >= 9.223372036854775808e18 )
228: error("drint : OverFlow");
229: a = (L)d;
230: if ( a < 0 ) {
231: sgn = -1;
232: a = -a;
233: } else
234: sgn = 1;
235: #if defined(i386) || defined(__alpha) || defined(VISUAL)
236: au = ((unsigned int *)&a)[1];
237: al = ((unsigned int *)&a)[0];
238: #else
239: al = ((unsigned int *)&a)[1];
240: au = ((unsigned int *)&a)[0];
241: #endif
242: if ( au ) {
243: NEWQ(q); SGN(q) = sgn; NM(q)=NALLOC(2); DN(q)=0;
244: PL(NM(q))=2; BD(NM(q))[0]=al; BD(NM(q))[1] = au;
245: } else {
246: UTOQ(al,q); SGN(q) = sgn;
247: }
248: *rp = q;
249: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>