Annotation of OpenXM_contrib2/asir2000/include/interval.h, Revision 1.4
1.1 saito 1: /*
1.4 ! saito 2: * $OpenXM: OpenXM_contrib2/asir2000/include/interval.h,v 1.3 2001/03/19 01:13:50 noro Exp $
1.1 saito 3: */
4: #ifndef _INTERVAL_H
5: #define _INTERVAL_H
6:
7: #define PRINTF_G 0
8: #define PRINTF_E 1
9:
10: #if defined(INTERVAL)
11:
12: #include <math.h>
13:
14: #ifdef sun
15: #if OSMajorVersion < 4 || (OSMajorVersion == 4 && OSMinorVersion < 1)
16: #include <sys/ieeefp.h>
17: #endif
18: #if defined(__svr4__)
19: #include <ieeefp.h>
20: #define FPNEAREST fpsetround(FP_RN);
21: #define FPPLUSINF fpsetround(FP_RP);
22: #define FPMINUSINF fpsetround(FP_RM);
23: #define FPTOZERO fpsetround(FP_RZ);
24: #else
25: static char *Interval_dummy;
26: #define FPNEAREST ieee_flags("clear", "direction", Interval_dummy, &Interval_dummy);
27: #define FPPLUSINF ieee_flags("set", "direction", "positive", &Interval_dummy);
28: #define FPMINUSINF ieee_flags("set", "direction", "negative", &Interval_dummy);
29: #define FPTOZERO ieee_flags("set", "direction", "tozero", &Interval_dummy);
30: #endif
31: #endif
32:
33: #ifdef linux
34: #include <fpu_control.h>
1.2 saito 35: #if 1
36: #define LINUX_FPU_RC_MASK 0xf3ff
37: #define LINUX_FPU_SETCW(c) {_FPU_GETCW(__fpu_control);\
38: _FPU_SETCW(__fpu_control & LINUX_FPU_RC_MASK | c);}
39: #define FPNEAREST LINUX_FPU_SETCW(_FPU_RC_NEAREST);
40: #define FPPLUSINF LINUX_FPU_SETCW(_FPU_RC_UP);
41: #define FPMINUSINF LINUX_FPU_SETCW(_FPU_RC_DOWN);
42: #define FPTOZERO LINUX_FPU_SETCW(_FPU_RC_ZERO);
43: #else
1.1 saito 44: #define _FPU_DEFAULT_p_FPU_RC_UP 0x1b72
45: #define _FPU_DEFAULT_p_FPU_RC_DOWN 0x1772
46: #define _FPU_DEFAULT_p_FPU_RC_ZERO 0x1f72
47: #define FPNEAREST __setfpucw(_FPU_DEFAULT);
48: #define FPPLUSINF __setfpucw(_FPU_DEFAULT_p_FPU_RC_UP);
49: #define FPMINUSINF __setfpucw(_FPU_DEFAULT_p_FPU_RC_DOWN);
50: #define FPTOZERO __setfpucw(_FPU_DEFAULT_p_FPU_RC_ZERO);
1.2 saito 51: #endif
1.1 saito 52: #endif
53:
54: #if defined(__osf__)
55: #if 0
56: #include <float.h>
57: #define FPNEAREST write_rnd(FP_RND_RN);
58: #define FPPLUSINF write_rnd(FP_RND_RP);
59: #define FPMINUSINF write_rnd(FP_RND_RM);
60: #define FPTOZERO write_rnd(FP_RND_RZ);
61: #else
62: #define FPNEAREST
63: #define FPPLUSINF
64: #define FPMINUSINF
65: #define FPTOZERO
66: #endif
67: #endif
68:
69: #if defined(__FreeBSD__)
70: #include <floatingpoint.h>
71: #define FPNEAREST fpsetround(FP_RN);
72: #define FPPLUSINF fpsetround(FP_RP);
73: #define FPMINUSINF fpsetround(FP_RM);
74: #define FPTOZERO fpsetround(FP_RZ);
75: #endif
76:
77: /* no control function of floating point rounding */
78: #ifndef FPNEAREST
79: #define FPNEAREST fprintf(stderr, "Fpu control FPNEAREST is not supported in this machine yet.\n");
80: #endif
81: #ifndef FPMINUSINF
82: #define FPMINUSINF fprintf(stderr, "Fpu control FPMINUSINF is not supported in this machine yet.\n");
83: #endif
84: #ifndef FPPLUSINF
85: #define FPPLUSINF fprintf(stderr, "Fpu control FPPLUSINF is not supported in this machine yet.\n");
86: #endif
87: #ifndef FPTOZERO
88: #define FPTOZERO fprintf(stderr, "Fpu control FPZERO is not supported in this machine yet.\n");
89: #endif
90: #define FPCLEAR FPNEAREST
91:
92: #define MID_PRINTF_G 2
93: #define MID_PRINTF_E 3
94:
95: #undef N_C
96: #undef N_M
97: #undef N_LM
98: #undef N_GF2N
99: #undef N_GFPN
1.3 noro 100: #undef N_GFS
1.4 ! saito 101: #undef N_GFSN
1.1 saito 102: #define N_IP (N_B+1)
103: #define N_ID (N_B+2)
104: #define N_IT (N_B+3)
105: #define N_IF (N_B+4)
106: #define N_PRE_C N_IF
107: #define N_C (N_B+5)
108: #define N_M (N_B+6)
109: #define N_LM (N_B+7)
110: #define N_GF2N (N_B+8)
111: #define N_GFPN (N_B+9)
1.3 noro 112: #define N_GFS (N_B+10)
1.4 ! saito 113: #define N_GFSN (N_B+11)
1.1 saito 114:
115: /* data structures */
116: struct oItv {
117: short id;
118: char nid;
119: char pad;
120: Num inf;
121: Num sup;
122: };
123:
124: typedef struct oItv *Itv;
125:
126: struct oItvD {
127: short id;
128: char nid;
129: char pad;
130: double inf;
131: double sup;
132: };
133:
134: typedef struct oItvD *ItvD;
135:
136: struct oforth {
137: short sign;
138: short exp;
139: double u;
140: double l;
141: };
142:
143: typedef struct oforth *forth;
144:
145: struct oItvT {
146: short id;
147: char nid;
148: char pad;
149: forth inf;
150: forth sup;
151: };
152:
153: typedef struct oItvT *ItvT;
154:
155: struct oItvF {
156: short id;
157: char nid;
158: char pad;
159: BF inf;
160: BF sup;
161: };
162:
163: typedef struct oItvF *ItvF;
164:
165: extern int zerorewrite;
166:
167: /* general macros */
168: #define INF(p) ((p)->inf)
169: #define SUP(p) ((p)->sup)
170:
171: #define NEWItvP(q) ((q)=(Itv)MALLOC(sizeof(struct oItv)),\
172: OID(q)=O_N,NID(q)=N_IP)
173: #define NEWItvD(q) ((q)=(ItvD)MALLOC(sizeof(struct oItvD)),\
174: OID(q)=O_N,NID(q)=N_ID)
175: #define NEWItvT(q) ((q)=(ItvD)MALLOC(sizeof(struct oItvT)),\
176: OID(q)=O_N,NID(q)=N_IT)
177: #define NEWItvF(q) ((q)=(ItvF)MALLOC(sizeof(struct oItvF)),\
178: OID(q)=O_N,NID(q)=N_IF)
179: #define MKItvP(a,b,c) (NEWItvP(c),(INF(c)=(a),SUP(c)=(b)))
180: #define MKItvD(a,b,c) if((zerorewrite) && ((a)<=0.0) && ((b)>=0.0)) (c)=0;\
181: else (NEWItvD(c),(INF(c)=(a),SUP(c)=(b)))
182: #define MKItvT(a,b,c) (NEWItvT(c),(INF(c)=(a),SUP(c)=(b)))
183: #define MKItvF(a,b,c) (NEWItvF(c),(INF(c)=(a),SUP(c)=(b)))
184:
185: #define ToItvP(a,c) (NEWItvP(c),INF(c)=(a),SUP(c)=(a))
186: #define ToItvD(a,c) (NEWItvD(c),INF(c)=(ToReal(a)),SUP(c)=(ToReal(a)))
187: #define ToItvF(a,c) (NEWItvF(c),INF(c)=(a),SUP(c)=(a))
188:
189: #define ITVP(a) (NID(a)==N_IP)
190: #define ITVD(a) (NID(a)==N_ID)
191: #define ITVT(a) (NID(a)==N_IT)
192: #define ITVF(a) (NID(a)==N_IF)
193:
194: /*** engine/itv.c ***/
195: double ToRealSup(Num);
196: double ToRealInf(Num);
197: double RatnToRealUp(Q);
198: double NatToRealUp(N, int *);
199:
200: void double2bf(double, BF *);
201: double bf2double(BF);
202:
203: void itvtois(Itv, Num *, Num *);
204: void istoitv(Num, Num, Itv *);
205:
206: #if 0
207: void additv(Num, Num, Num *);
208: void subitv(Num, Num, Num *);
209: void mulitv(Num, Num, Num *);
210: int initv(Num, double);
211: int itvinitv(Itv, Itv);
212: void divitv(Num, Num, Num *);
213: void sqrtitv(Num, Num *);
214: void pwritv(Num, Num, Num *);
215: void pwritv0(Itv, int, Itv *);
216: void chsgnitv(Num, Num *);
217: void miditv(Itv, Num *);
218: int cmpitv(Itv, Itv);
219: void cupitv(Itv, Itv, Itv *);
220: void capitv(Itv, Itv, Itv *);
221: void widthitv(Itv, Num *);
222: void distanceitv(Itv, Itv, Num *);
223: #endif
224:
225: void additvp(Itv, Itv, Itv *);
226: void subitvp(Itv, Itv, Itv *);
227: void mulitvp(Itv, Itv, Itv *);
228: void divitvp(Itv, Itv, Itv *);
229: void chsgnitvp(Itv, Itv *);
230: int cmpitvp(Itv, Itv);
231: void pwritvp(Itv, Num, Itv *);
232: void pwritv0p(Itv, int, Itv *);
233: void cupitvp(Itv, Itv, Itv *);
234: void capitvp(Itv, Itv, Itv *);
235: void widthitvp(Itv, Num *);
236: void distanceitvp(Itv, Itv, Num *);
237:
238: void ToBf(Num, BF *);
239: void double2bf(double, BF *);
240: double bf2double(BF);
241: void addulp(ItvF, ItvF *);
242: void getulp(BF, BF *);
243:
244: void additvf(ItvF, ItvF, ItvF *);
245: void subitvf(ItvF, ItvF, ItvF *);
246: void mulitvf(ItvF, ItvF, ItvF *);
247: void divitvf(ItvF, ItvF, ItvF *);
248: void chsgnitvf(Itv, Itv *);
249: int cmpitvf(Itv, Itv);
250: void pwritvf(Itv, Num, Itv *);
251: void pwritv0f(Itv, int, Itv *);
252:
253: /*** engine/d-itv.c ***/
254: double ToRealDown(Num);
255: double ToRealUp(Num);
256: void Num2double(Num, double *, double *);
257:
258: void additvd(Num, Num, ItvD *);
259: void subitvd(Num, Num, ItvD *);
260: void mulitvd(Num, Num, ItvD *);
261: void divitvd(Num, Num, ItvD *);
262: void chsgnitvd(ItvD, ItvD *);
263: int cmpitvd(ItvD, ItvD);
264: void pwritvd(Num, Num, ItvD *);
265: void pwritv0d(ItvD, int, ItvD *);
266: void miditvd(ItvD, Num *);
267: void cupitvd(ItvD, ItvD, ItvD *);
268: void capitvd(ItvD, ItvD, ItvD *);
269: void widthitvd(ItvD, Num *);
270: void absitvd(ItvD, Num *);
271: void distanceitvd(ItvD, ItvD, Num *);
272:
273: #endif /* end of INTERVAL */
274: #endif /* end of _INTERVAL_H */
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>