Annotation of OpenXM_contrib2/asir2000/builtin/round.c, Revision 1.3
1.3 ! noro 1: /* $OpenXM: OpenXM_contrib2/asir2000/builtin/round.c,v 1.2 2003/12/02 03:26:14 noro Exp $ */
1.2 noro 2:
1.1 noro 3: #define INTERVAL
4: #include "ca.h"
5: #include "parse.h"
6: #include "interval.h"
7:
8: void Padd_pinf(),Padd_minf();
9: void Psub_pinf(),Psub_minf();
10: void Pmul_pinf(),Pmul_minf();
11: void Pdiv_pinf(),Pdiv_minf();
12:
13: struct ftab round_tab[] = {
14: {"add_pinf",Padd_pinf,2},
15: {"add_minf",Padd_minf,2},
16: {"sub_pinf",Psub_pinf,2},
17: {"sub_minf",Psub_minf,2},
18: {"mul_pinf",Pmul_pinf,2},
19: {"mul_minf",Pmul_minf,2},
20: {"div_pinf",Pdiv_pinf,2},
21: {"div_minf",Pdiv_minf,2},
22: {0,0,0},
23: };
24:
25: void Padd_pinf(NODE arg,Real *rp)
26: {
27: Real a,b,r;
28: double c;
29:
30: a = (Real)ARG0(arg);
31: b = (Real)ARG1(arg);
32: if ( !a )
33: *rp = b;
34: else if ( !b )
35: *rp = a;
1.3 ! noro 36: else if ( NID(a) != N_R || NID(b) != N_R )
! 37: error("add_pinf : invalid argument");
1.1 noro 38: else {
39: FPPLUSINF
40: c = BDY(a)+BDY(b);
41: FPNEAREST
42: MKReal(c,r);
43: *rp = r;
44: }
45: }
46:
47: void Padd_minf(NODE arg,Real *rp)
48: {
49: Real a,b,r;
50: double c;
51:
52: a = (Real)ARG0(arg);
53: b = (Real)ARG1(arg);
54: if ( !a )
55: *rp = b;
56: else if ( !b )
57: *rp = a;
1.3 ! noro 58: else if ( NID(a) != N_R || NID(b) != N_R )
! 59: error("add_pinf : invalid argument");
1.1 noro 60: else {
61: FPMINUSINF
62: c = BDY(a)+BDY(b);
63: FPNEAREST
64: MKReal(c,r);
65: *rp = r;
66: }
67: }
68:
69: void Psub_pinf(NODE arg,Real *rp)
70: {
71: Real a,b,r;
72: double c;
73:
74: a = (Real)ARG0(arg);
75: b = (Real)ARG1(arg);
76: if ( !a ) {
77: if ( !b )
78: *rp = 0;
79: else {
80: c = -BDY(b);
81: MKReal(c,r);
82: *rp = r;
83: }
84: } else if ( !b )
85: *rp = a;
1.3 ! noro 86: else if ( NID(a) != N_R || NID(b) != N_R )
! 87: error("sub_pinf : invalid argument");
1.1 noro 88: else {
89: FPPLUSINF
90: c = BDY(a)-BDY(b);
91: FPNEAREST
92: MKReal(c,r);
93: *rp = r;
94: }
95: }
96:
97: void Psub_minf(NODE arg,Real *rp)
98: {
99: Real a,b,r;
100: double c;
101:
102: a = (Real)ARG0(arg);
103: b = (Real)ARG1(arg);
104: if ( !a ) {
105: if ( !b )
106: *rp = 0;
107: else {
108: c = -BDY(b);
109: MKReal(c,r);
110: *rp = r;
111: }
112: } else if ( !b )
113: *rp = a;
1.3 ! noro 114: else if ( NID(a) != N_R || NID(b) != N_R )
! 115: error("sub_minf : invalid argument");
1.1 noro 116: else {
117: FPMINUSINF
118: c = BDY(a)-BDY(b);
119: FPNEAREST
120: MKReal(c,r);
121: *rp = r;
122: }
123: }
124:
125: void Pmul_pinf(NODE arg,Real *rp)
126: {
127: Real a,b,r;
128: double c;
129:
130: a = (Real)ARG0(arg);
131: b = (Real)ARG1(arg);
132: if ( !a || !b )
133: *rp = 0;
1.3 ! noro 134: else if ( NID(a) != N_R || NID(b) != N_R )
! 135: error("mul_pinf : invalid argument");
1.1 noro 136: else {
137: FPPLUSINF
138: c = BDY(a)*BDY(b);
139: FPNEAREST
140: MKReal(c,r);
141: *rp = r;
142: }
143: }
144:
145: void Pmul_minf(NODE arg,Real *rp)
146: {
147: Real a,b,r;
148: double c;
149:
150: a = (Real)ARG0(arg);
151: b = (Real)ARG1(arg);
152: if ( !a || !b )
153: *rp = 0;
1.3 ! noro 154: else if ( NID(a) != N_R || NID(b) != N_R )
! 155: error("mul_minf : invalid argument");
1.1 noro 156: else {
157: FPMINUSINF
158: c = BDY(a)*BDY(b);
159: FPNEAREST
160: MKReal(c,r);
161: *rp = r;
162: }
163: }
164:
165: void Pdiv_pinf(NODE arg,Real *rp)
166: {
167: Real a,b,r;
168: double c;
169:
170: a = (Real)ARG0(arg);
171: b = (Real)ARG1(arg);
172: if ( !b )
173: error("div_pinf : division by 0");
174: else if ( !a )
175: *rp = 0;
1.3 ! noro 176: else if ( NID(a) != N_R || NID(b) != N_R )
! 177: error("div_pinf : invalid argument");
1.1 noro 178: else {
179: FPPLUSINF
180: c = BDY(a)/BDY(b);
181: FPNEAREST
182: MKReal(c,r);
183: *rp = r;
184: }
185: }
186:
187: void Pdiv_minf(NODE arg,Real *rp)
188: {
189: Real a,b,r;
190: double c;
191:
192: a = (Real)ARG0(arg);
193: b = (Real)ARG1(arg);
194: if ( !b )
1.3 ! noro 195: error("div_minf : division by 0");
1.1 noro 196: else if ( !a )
197: *rp = 0;
1.3 ! noro 198: else if ( NID(a) != N_R || NID(b) != N_R )
! 199: error("div_minf : invalid argument");
1.1 noro 200: else {
201: FPMINUSINF
202: c = BDY(a)/BDY(b);
203: FPNEAREST
204: MKReal(c,r);
205: *rp = r;
206: }
207: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>