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