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