Annotation of OpenXM_contrib2/asir2018/include/interval.h, Revision 1.5
1.1 noro 1: /*
1.5 ! kondoh 2: * $OpenXM: OpenXM_contrib2/asir2018/include/interval.h,v 1.4 2019/11/12 10:53:23 kondoh Exp $
1.1 noro 3: */
4: #ifndef _INTERVAL_H
5: #define _INTERVAL_H
6:
7: #define PRINTF_G 0
8: #define PRINTF_E 1
9:
1.5 ! kondoh 10: #define INT_ASIR_VERSION 20191219
1.2 kondoh 11:
1.1 noro 12: #if defined(INTERVAL)
1.4 kondoh 13: #if INTERVAL == 0
14: #undef INTERVAL
15: #endif
16: #endif
17: #if defined(INTERVAL)
1.1 noro 18:
19: #include <math.h>
20:
21: #ifdef sun
22: #if OSMajorVersion < 4 || (OSMajorVersion == 4 && OSMinorVersion < 1)
23: #include <sys/ieeefp.h>
24: #endif
25: #if defined(__svr4__)
26: #include <ieeefp.h>
27: #define FPNEAREST fpsetround(FP_RN);
28: #define FPPLUSINF fpsetround(FP_RP);
29: #define FPMINUSINF fpsetround(FP_RM);
30: #define FPTOZERO fpsetround(FP_RZ);
31: #else
32: static char *Interval_dummy;
33: #define FPNEAREST ieee_flags("clear", "direction", Interval_dummy, &Interval_dummy);
34: #define FPPLUSINF ieee_flags("set", "direction", "positive", &Interval_dummy);
35: #define FPMINUSINF ieee_flags("set", "direction", "negative", &Interval_dummy);
36: #define FPTOZERO ieee_flags("set", "direction", "tozero", &Interval_dummy);
37: #endif
38: #endif
39:
1.2 kondoh 40: #if 0
1.1 noro 41: #ifdef linux
42: #include <fpu_control.h>
43: #if 1
44:
45: #if defined(__ARM_ARCH) || defined(ANDROID)
46: #ifndef _FPU_RC_NEAREST
47: #define _FPU_RC_NEAREST 0x0
48: #endif
49: #ifndef _FPU_RC_DOWN
50: #define _FPU_RC_DOWN 0x400
51: #endif
52: #ifndef _FPU_RC_UP
53: #define _FPU_RC_UP 0x800
54: #endif
55: #ifndef _FPU_RC_ZERO
56: #define _FPU_RC_ZERO 0xC00
57: #endif
58: #endif /* __ARM_ARCH */
59:
60: #define LINUX_FPU_RC_MASK 0xf3ff
61: #define LINUX_FPU_SETCW(c) \
62: {fpu_control_t __tmp__; _FPU_GETCW(__fpu_control);\
63: __tmp__ = (__fpu_control & LINUX_FPU_RC_MASK | c);\
64: _FPU_SETCW(__tmp__);}
65: #define FPNEAREST LINUX_FPU_SETCW(_FPU_RC_NEAREST);
66: #define FPPLUSINF LINUX_FPU_SETCW(_FPU_RC_UP);
67: #define FPMINUSINF LINUX_FPU_SETCW(_FPU_RC_DOWN);
68: #define FPTOZERO LINUX_FPU_SETCW(_FPU_RC_ZERO);
69: #else
70: #define _FPU_DEFAULT_p_FPU_RC_UP 0x1b72
71: #define _FPU_DEFAULT_p_FPU_RC_DOWN 0x1772
72: #define _FPU_DEFAULT_p_FPU_RC_ZERO 0x1f72
73: #define FPNEAREST __setfpucw(_FPU_DEFAULT);
74: #define FPPLUSINF __setfpucw(_FPU_DEFAULT_p_FPU_RC_UP);
75: #define FPMINUSINF __setfpucw(_FPU_DEFAULT_p_FPU_RC_DOWN);
76: #define FPTOZERO __setfpucw(_FPU_DEFAULT_p_FPU_RC_ZERO);
77: #endif
78: #endif
79:
80: #if defined(__osf__)
81: #if 0
82: #include <float.h>
83: #define FPNEAREST write_rnd(FP_RND_RN);
84: #define FPPLUSINF write_rnd(FP_RND_RP);
85: #define FPMINUSINF write_rnd(FP_RND_RM);
86: #define FPTOZERO write_rnd(FP_RND_RZ);
87: #else
88: #define FPNEAREST
89: #define FPPLUSINF
90: #define FPMINUSINF
91: #define FPTOZERO
92: #endif
93: #endif
94:
95: #if defined(__FreeBSD__) && defined(__GNUC__)
96: #include <floatingpoint.h>
97: #define FPNEAREST fpsetround(FP_RN);
98: #define FPPLUSINF fpsetround(FP_RP);
99: #define FPMINUSINF fpsetround(FP_RM);
100: #define FPTOZERO fpsetround(FP_RZ);
101: #endif
102:
103: #if defined(VISUAL) || defined(__MINGW32__)
104: #include <float.h>
105: #define FPNEAREST _controlfp(_RC_NEAR,_MCW_RC);
106: #define FPPLUSINF _controlfp(_RC_UP,_MCW_RC);
107: #define FPMINUSINF _controlfp(_RC_DOWN,_MCW_RC);
108: #define FPTOZERO _controlfp(_RC_CHOP,_MCW_RC);
109: #endif
1.2 kondoh 110: #endif
111: #include <fenv.h>
112:
113: #define FPNEAREST fesetround(FE_TONEAREST);
114: #define FPPLUSINF fesetround(FE_UPWARD);
115: #define FPMINUSINF fesetround(FE_DOWNWARD);
116: #define FPTOZERO fesetround(FE_TOWARDZERO);
117:
1.1 noro 118:
119: /* no control function of floating point rounding */
120: #ifndef FPNEAREST
121: #define FPNEAREST fprintf(stderr, "Fpu control FPNEAREST is not supported in this machine yet.\n");
122: #endif
123: #ifndef FPMINUSINF
124: #define FPMINUSINF fprintf(stderr, "Fpu control FPMINUSINF is not supported in this machine yet.\n");
125: #endif
126: #ifndef FPPLUSINF
127: #define FPPLUSINF fprintf(stderr, "Fpu control FPPLUSINF is not supported in this machine yet.\n");
128: #endif
129: #ifndef FPTOZERO
130: #define FPTOZERO fprintf(stderr, "Fpu control FPZERO is not supported in this machine yet.\n");
131: #endif
132: #define FPCLEAR FPNEAREST
133:
134: #define MID_PRINTF_G 2
135: #define MID_PRINTF_E 3
136:
1.2 kondoh 137: #define DEFAULTPREC 0 /* for mpfr */
138:
1.1 noro 139: /* data structures */
140: struct oItv {
141: short id;
142: char nid;
143: char pad;
144: Num inf;
145: Num sup;
146: };
147:
148: typedef struct oItv *Itv;
149:
150: struct oIntervalDouble {
151: short id;
152: char nid;
153: char pad;
154: double inf;
155: double sup;
156: };
157:
158: typedef struct oIntervalDouble *IntervalDouble;
159:
160: struct oforth {
161: short sign;
162: short exp;
163: double u;
164: double l;
165: };
166:
167: typedef struct oforth *forth;
168:
169: struct oIntervalQuad {
170: short id;
171: char nid;
172: char pad;
173: forth inf;
174: forth sup;
175: };
176:
177: typedef struct oIntervalQuad *IntervalQuad;
178:
179: struct oIntervalBigFloat {
180: short id;
181: char nid;
182: char pad;
183: BF inf;
184: BF sup;
185: };
186:
187: typedef struct oIntervalBigFloat *IntervalBigFloat;
188:
189: extern int zerorewrite;
1.2 kondoh 190: extern int zerorewriteCount;
1.1 noro 191:
1.4 kondoh 192: #define ZEROREWRITE if (zerorewrite && initvp(0,c) ) { *rp = 0; zerorewriteCount++; }
193:
1.1 noro 194: /* general macros */
195: #define INF(p) ((p)->inf)
196: #define SUP(p) ((p)->sup)
197:
198: #define NEWItvP(q) ((q)=(Itv)MALLOC(sizeof(struct oItv)),\
199: OID(q)=O_N,NID(q)=N_IP)
200: #define NEWIntervalDouble(q) ((q)=(IntervalDouble)MALLOC(sizeof(struct oIntervalDouble)),\
201: OID(q)=O_N,NID(q)=N_IntervalDouble)
202: #define NEWIntervalQuad(q) ((q)=(IntervalDouble)MALLOC(sizeof(struct oIntervalQuad)),\
203: OID(q)=O_N,NID(q)=N_IntervalQuad)
204: #define NEWIntervalBigFloat(q) ((q)=(IntervalBigFloat)MALLOC(sizeof(struct oIntervalBigFloat)),\
205: OID(q)=O_N,NID(q)=N_IntervalBigFloat)
206: #define MKItvP(a,b,c) (NEWItvP(c),(INF(c)=(a),SUP(c)=(b)))
1.2 kondoh 207: #define MKIntervalDouble(a,b,c) if((zerorewrite) && ((a)<=0.0) && ((b)>=0.0)) {(c)=0;zerorewriteCount++;}\
208: else (NEWIntervalDouble(c),(INF(c)=(a),SUP(c)=(b)))
1.1 noro 209: #define MKIntervalQuad(a,b,c) (NEWIntervalQuad(c),(INF(c)=(a),SUP(c)=(b)))
210: #define MKIntervalBigFloat(a,b,c) (NEWIntervalBigFloat(c),(INF(c)=(a),SUP(c)=(b)))
211:
212: #define ToItvP(a,c) (NEWItvP(c),INF(c)=(a),SUP(c)=(a))
1.4 kondoh 213: #define ToIntervalDouble(a,c) (NEWIntervalDouble(c),INF(c)=(toRealDown(a)),SUP(c)=(toRealUp(a)))
1.1 noro 214: #define ToIntervalBigFloat(a,c) (NEWIntervalBigFloat(c),INF(c)=(a),SUP(c)=(a))
215:
216: #define ITVP(a) (NID(a)==N_IP)
217: #define ITVD(a) (NID(a)==N_IntervalDouble)
218: #define ITVQ(a) (NID(a)==N_IntervalQuad)
219: #define ITVF(a) (NID(a)==N_IntervalBigFloat)
220:
1.4 kondoh 221: #define EvalIntervalDouble 0
222: #define EvalIntervalQuad 1
223: #define EvalIntervalBigFloat 2
224:
1.2 kondoh 225: /*** engine/p-itv.c ***/
226: void itvtois(Itv, Num *, Num *);
227: void istoitv(Num, Num, Itv *);
228:
1.1 noro 229: void additvp(Itv, Itv, Itv *);
230: void subitvp(Itv, Itv, Itv *);
231: void mulitvp(Itv, Itv, Itv *);
232: void divitvp(Itv, Itv, Itv *);
1.2 kondoh 233: void pwritvp(Itv, Num, Itv *);
1.3 kondoh 234: void pwritv0p(Itv, long, Itv *);
1.1 noro 235: void chsgnitvp(Itv, Itv *);
1.2 kondoh 236: int initvp(Num , Itv );
237: int itvinitvp(Itv, Itv);
1.1 noro 238: int cmpitvp(Itv, Itv);
1.2 kondoh 239: void miditvp(Itv, Num *);
1.1 noro 240: void cupitvp(Itv, Itv, Itv *);
241: void capitvp(Itv, Itv, Itv *);
242: void widthitvp(Itv, Num *);
1.4 kondoh 243: void absitvp(Itv, Num *);
244: void absintvalp(Itv, Itv *);
1.1 noro 245: void distanceitvp(Itv, Itv, Num *);
246:
1.2 kondoh 247:
248: /*** engine/f-itv.c ***/
249:
250: //void ToBf(Num, BF *);
251: //void double2bf(double, BF *);
252: //double bf2double(BF);
253: //void addulp(IntervalBigFloat, IntervalBigFloat *);
254: //void getulp(BF, BF *);
1.4 kondoh 255: double mpfr2dblDown(mpfr_t);
256: double mpfr2dblUp(mpfr_t);
257: void toInterval(Num, int, int, Num *);
1.1 noro 258:
259: void additvf(IntervalBigFloat, IntervalBigFloat, IntervalBigFloat *);
260: void subitvf(IntervalBigFloat, IntervalBigFloat, IntervalBigFloat *);
261: void mulitvf(IntervalBigFloat, IntervalBigFloat, IntervalBigFloat *);
262: void divitvf(IntervalBigFloat, IntervalBigFloat, IntervalBigFloat *);
1.2 kondoh 263: void chsgnitvf(IntervalBigFloat, IntervalBigFloat *);
264: int initvf(Num, Itv);
265: int itvinitvf(Itv, Itv);
1.1 noro 266: int cmpitvf(Itv, Itv);
267: void pwritvf(Itv, Num, Itv *);
1.3 kondoh 268: void pwritv0f(Itv, long, Itv *);
1.2 kondoh 269: void miditvf(Itv, Num *);
270: void cupitvf(Itv, Itv, Itv *);
271: void capitvf(Itv, Itv, Itv *);
272: void widthitvf(Itv, Num *);
273: void absitvf(Itv, Num *);
274: void distanceitvf(Itv, Itv, Num *);
1.1 noro 275:
276: /*** engine/d-itv.c ***/
1.4 kondoh 277: double toRealDown(Num);
278: double toRealUp(Num);
1.1 noro 279: void Num2double(Num, double *, double *);
280:
281: void additvd(Num, Num, IntervalDouble *);
282: void subitvd(Num, Num, IntervalDouble *);
283: void mulitvd(Num, Num, IntervalDouble *);
284: void divitvd(Num, Num, IntervalDouble *);
285: void chsgnitvd(IntervalDouble, IntervalDouble *);
1.2 kondoh 286: int initvd(Num, IntervalDouble);
1.1 noro 287: int cmpitvd(IntervalDouble, IntervalDouble);
288: void pwritvd(Num, Num, IntervalDouble *);
1.3 kondoh 289: void pwritv0d(IntervalDouble, long, IntervalDouble *);
1.1 noro 290: void miditvd(IntervalDouble, Num *);
291: void cupitvd(IntervalDouble, IntervalDouble, IntervalDouble *);
292: void capitvd(IntervalDouble, IntervalDouble, IntervalDouble *);
293: void widthitvd(IntervalDouble, Num *);
294: void absitvd(IntervalDouble, Num *);
1.4 kondoh 295: void absintvald(IntervalDouble, IntervalDouble *);
1.1 noro 296: void distanceitvd(IntervalDouble, IntervalDouble, Num *);
297:
1.4 kondoh 298: /*** builtin/itvnum.c ***/
299:
300: void evalitvr(VL ,Obj ,int , int , Obj *);
301: void evalitvp(VL ,P ,int , int , P *);
302: void evalitvv(VL ,V ,int , int , Obj *);
1.5 ! kondoh 303:
1.4 kondoh 304: extern void (*pi_itv_ft[])();
305: extern void (*e_itv_ft[])();
306: extern void (*sin_itv_ft[])();
307: extern void (*cos_itv_ft[])();
308: extern void (*tan_itv_ft[])();
309: extern void (*asin_itv_ft[])();
310: extern void (*acos_itv_ft[])();
311: extern void (*atan_itv_ft[])();
312: extern void (*sinh_itv_ft[])();
313: extern void (*cosh_itv_ft[])();
314: extern void (*tanh_itv_ft[])();
315: extern void (*asinh_itv_ft[])();
316: extern void (*acosh_itv_ft[])();
317: extern void (*atanh_itv_ft[])();
318: extern void (*exp_itv_ft[])();
319: extern void (*log_itv_ft[])();
320: extern void (*abs_itv_ft[])();
321: extern void (*pow_itv_ft[])();
322:
1.1 noro 323: #endif /* end of INTERVAL */
324: #endif /* end of _INTERVAL_H */
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>