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