Annotation of OpenXM_contrib2/asir2000/include/interval.h, Revision 1.6
1.1 saito 1: /*
1.6 ! fujiwara 2: * $OpenXM: OpenXM_contrib2/asir2000/include/interval.h,v 1.5 2002/01/08 04:14:38 kondoh 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);
1.6 ! fujiwara 75: #endif
! 76:
! 77: #if defined(VISUAL)
! 78: #include <float.h>
! 79: #define FPNEAREST _controlfp(_RC_NEAR,_MCW_RC);
! 80: #define FPPLUSINF _controlfp(_RC_UP,_MCW_RC);
! 81: #define FPMINUSINF _controlfp(_RC_DOWN,_MCW_RC);
! 82: #define FPTOZERO _controlfp(_RC_CHOP,_MCW_RC);
1.1 saito 83: #endif
84:
85: /* no control function of floating point rounding */
86: #ifndef FPNEAREST
87: #define FPNEAREST fprintf(stderr, "Fpu control FPNEAREST is not supported in this machine yet.\n");
88: #endif
89: #ifndef FPMINUSINF
90: #define FPMINUSINF fprintf(stderr, "Fpu control FPMINUSINF is not supported in this machine yet.\n");
91: #endif
92: #ifndef FPPLUSINF
93: #define FPPLUSINF fprintf(stderr, "Fpu control FPPLUSINF is not supported in this machine yet.\n");
94: #endif
95: #ifndef FPTOZERO
96: #define FPTOZERO fprintf(stderr, "Fpu control FPZERO is not supported in this machine yet.\n");
97: #endif
98: #define FPCLEAR FPNEAREST
99:
100: #define MID_PRINTF_G 2
101: #define MID_PRINTF_E 3
102:
103: #undef N_C
104: #undef N_M
105: #undef N_LM
106: #undef N_GF2N
107: #undef N_GFPN
1.3 noro 108: #undef N_GFS
1.4 saito 109: #undef N_GFSN
1.5 kondoh 110: #define N_NEXT_B (N_B+1)
111: #define N_Quad (N_NEXT_B)
112: #define N_IP (N_NEXT_B+1)
113: #define N_IntervalDouble (N_NEXT_B+2)
114: #define N_IntervalQuad (N_NEXT_B+3)
115: #define N_IntervalBigFloat (N_NEXT_B+4)
116: #define N_PRE_C N_IntervalBigFloat
117: #define N_C (N_NEXT_B+5)
118: #define N_M (N_NEXT_B+6)
119: #define N_LM (N_NEXT_B+7)
120: #define N_GF2N (N_NEXT_B+8)
121: #define N_GFPN (N_NEXT_B+9)
122: #define N_GFS (N_NEXT_B+10)
123: #define N_GFSN (N_NEXT_B+11)
1.1 saito 124:
125: /* data structures */
126: struct oItv {
127: short id;
128: char nid;
129: char pad;
130: Num inf;
131: Num sup;
132: };
133:
134: typedef struct oItv *Itv;
135:
1.5 kondoh 136: struct oIntervalDouble {
1.1 saito 137: short id;
138: char nid;
139: char pad;
140: double inf;
141: double sup;
142: };
143:
1.5 kondoh 144: typedef struct oIntervalDouble *IntervalDouble;
1.1 saito 145:
146: struct oforth {
147: short sign;
148: short exp;
149: double u;
150: double l;
151: };
152:
153: typedef struct oforth *forth;
154:
1.5 kondoh 155: struct oIntervalQuad {
1.1 saito 156: short id;
157: char nid;
158: char pad;
159: forth inf;
160: forth sup;
161: };
162:
1.5 kondoh 163: typedef struct oIntervalQuad *IntervalQuad;
1.1 saito 164:
1.5 kondoh 165: struct oIntervalBigFloat {
1.1 saito 166: short id;
167: char nid;
168: char pad;
169: BF inf;
170: BF sup;
171: };
172:
1.5 kondoh 173: typedef struct oIntervalBigFloat *IntervalBigFloat;
1.1 saito 174:
175: extern int zerorewrite;
176:
177: /* general macros */
178: #define INF(p) ((p)->inf)
179: #define SUP(p) ((p)->sup)
180:
181: #define NEWItvP(q) ((q)=(Itv)MALLOC(sizeof(struct oItv)),\
182: OID(q)=O_N,NID(q)=N_IP)
1.5 kondoh 183: #define NEWIntervalDouble(q) ((q)=(IntervalDouble)MALLOC(sizeof(struct oIntervalDouble)),\
184: OID(q)=O_N,NID(q)=N_IntervalDouble)
185: #define NEWIntervalQuad(q) ((q)=(IntervalDouble)MALLOC(sizeof(struct oIntervalQuad)),\
186: OID(q)=O_N,NID(q)=N_IntervalQuad)
187: #define NEWIntervalBigFloat(q) ((q)=(IntervalBigFloat)MALLOC(sizeof(struct oIntervalBigFloat)),\
188: OID(q)=O_N,NID(q)=N_IntervalBigFloat)
1.1 saito 189: #define MKItvP(a,b,c) (NEWItvP(c),(INF(c)=(a),SUP(c)=(b)))
1.5 kondoh 190: #define MKIntervalDouble(a,b,c) if((zerorewrite) && ((a)<=0.0) && ((b)>=0.0)) (c)=0;\
191: else (NEWIntervalDouble(c),(INF(c)=(a),SUP(c)=(b)))
192: #define MKIntervalQuad(a,b,c) (NEWIntervalQuad(c),(INF(c)=(a),SUP(c)=(b)))
193: #define MKIntervalBigFloat(a,b,c) (NEWIntervalBigFloat(c),(INF(c)=(a),SUP(c)=(b)))
1.1 saito 194:
195: #define ToItvP(a,c) (NEWItvP(c),INF(c)=(a),SUP(c)=(a))
1.5 kondoh 196: #define ToIntervalDouble(a,c) (NEWIntervalDouble(c),INF(c)=(ToReal(a)),SUP(c)=(ToReal(a)))
197: #define ToIntervalBigFloat(a,c) (NEWIntervalBigFloat(c),INF(c)=(a),SUP(c)=(a))
1.1 saito 198:
199: #define ITVP(a) (NID(a)==N_IP)
1.5 kondoh 200: #define ITVD(a) (NID(a)==N_IntervalDouble)
201: #define ITVQ(a) (NID(a)==N_IntervalQuad)
202: #define ITVF(a) (NID(a)==N_IntervalBigFloat)
1.1 saito 203:
204: /*** engine/itv.c ***/
205: double ToRealSup(Num);
206: double ToRealInf(Num);
207: double RatnToRealUp(Q);
208: double NatToRealUp(N, int *);
209:
210: void double2bf(double, BF *);
211: double bf2double(BF);
212:
213: void itvtois(Itv, Num *, Num *);
214: void istoitv(Num, Num, Itv *);
215:
216: #if 0
217: void additv(Num, Num, Num *);
218: void subitv(Num, Num, Num *);
219: void mulitv(Num, Num, Num *);
220: int initv(Num, double);
221: int itvinitv(Itv, Itv);
222: void divitv(Num, Num, Num *);
223: void sqrtitv(Num, Num *);
224: void pwritv(Num, Num, Num *);
225: void pwritv0(Itv, int, Itv *);
226: void chsgnitv(Num, Num *);
227: void miditv(Itv, Num *);
228: int cmpitv(Itv, Itv);
229: void cupitv(Itv, Itv, Itv *);
230: void capitv(Itv, Itv, Itv *);
231: void widthitv(Itv, Num *);
232: void distanceitv(Itv, Itv, Num *);
233: #endif
234:
235: void additvp(Itv, Itv, Itv *);
236: void subitvp(Itv, Itv, Itv *);
237: void mulitvp(Itv, Itv, Itv *);
238: void divitvp(Itv, Itv, Itv *);
239: void chsgnitvp(Itv, Itv *);
240: int cmpitvp(Itv, Itv);
241: void pwritvp(Itv, Num, Itv *);
242: void pwritv0p(Itv, int, Itv *);
243: void cupitvp(Itv, Itv, Itv *);
244: void capitvp(Itv, Itv, Itv *);
245: void widthitvp(Itv, Num *);
246: void distanceitvp(Itv, Itv, Num *);
247:
248: void ToBf(Num, BF *);
249: void double2bf(double, BF *);
250: double bf2double(BF);
1.5 kondoh 251: void addulp(IntervalBigFloat, IntervalBigFloat *);
1.1 saito 252: void getulp(BF, BF *);
253:
1.5 kondoh 254: void additvf(IntervalBigFloat, IntervalBigFloat, IntervalBigFloat *);
255: void subitvf(IntervalBigFloat, IntervalBigFloat, IntervalBigFloat *);
256: void mulitvf(IntervalBigFloat, IntervalBigFloat, IntervalBigFloat *);
257: void divitvf(IntervalBigFloat, IntervalBigFloat, IntervalBigFloat *);
1.1 saito 258: void chsgnitvf(Itv, Itv *);
259: int cmpitvf(Itv, Itv);
260: void pwritvf(Itv, Num, Itv *);
261: void pwritv0f(Itv, int, Itv *);
262:
263: /*** engine/d-itv.c ***/
264: double ToRealDown(Num);
265: double ToRealUp(Num);
266: void Num2double(Num, double *, double *);
267:
1.5 kondoh 268: void additvd(Num, Num, IntervalDouble *);
269: void subitvd(Num, Num, IntervalDouble *);
270: void mulitvd(Num, Num, IntervalDouble *);
271: void divitvd(Num, Num, IntervalDouble *);
272: void chsgnitvd(IntervalDouble, IntervalDouble *);
273: int cmpitvd(IntervalDouble, IntervalDouble);
274: void pwritvd(Num, Num, IntervalDouble *);
275: void pwritv0d(IntervalDouble, int, IntervalDouble *);
276: void miditvd(IntervalDouble, Num *);
277: void cupitvd(IntervalDouble, IntervalDouble, IntervalDouble *);
278: void capitvd(IntervalDouble, IntervalDouble, IntervalDouble *);
279: void widthitvd(IntervalDouble, Num *);
280: void absitvd(IntervalDouble, Num *);
281: void distanceitvd(IntervalDouble, IntervalDouble, Num *);
1.1 saito 282:
283: #endif /* end of INTERVAL */
284: #endif /* end of _INTERVAL_H */
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>