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