defines.h
Go to the documentation of this file.
1 #ifndef DEFINESH
2 #define DEFINESH
3 
4 #include "error.h" /*The NEW macros call error()*/
5 #include <stdlib.h> /*The NEW macros call malloc,..*/
6 #include <fenv.h> /*FPU control*/
7 
18 /************************************************************************************/
19 /************************************************************************************/
37 #define ZERO 1e-11
38 
55 #define RANDOMNESS (_DEBUG<2)
56 
57 /************************************************************************************/
58 /************************************************************************************/
59 
65 #if (_SIMPLEX_ENGINE==_CLP)
66  #include <coin/Coin_C_defines.h>
67  #include <float.h>
68 
69  #ifndef COIN_DBL_MAX
70  #define INF DBL_MAX
71  #else
72  #define INF COIN_DBL_MAX
73  #endif
74 #else
75  #define INF 1e10
76 #endif
77 
78 #ifndef M_PI
79 
83  #define M_PI 3.14159265358979323846
84 #endif
85 
86 
87 #ifndef M_PI_2
88 
92  #define M_PI_2 1.57079632679489661923
93 #endif
94 
95 #ifndef M_2PI
96 
100  #define M_2PI (2.0*M_PI)
101 #endif
102 
103 
104 #ifndef M_E
105 
109  #define M_E 2.718281828459045
110 #endif
111 
112 
113 
114 
115 /************************************************************************************/
116 /************************************************************************************/
117 
122 #define TOPOLOGY_R 1
123 
139 #define TOPOLOGY_S 2
140 
141 /************************************************************************************/
142 /************************************************************************************/
148 #define MAX_INCLUDES 100
149 
150 /************************************************************************************/
151 /************************************************************************************/
161 #define SWAP(a,b,c) {c=a;a=b;b=c;}
162 
163 /************************************************************************************/
164 /************************************************************************************/
169 #define DEG2RAD (M_PI/180.0)
170 
175 #define RAD2DEG (180.0/M_PI)
176 
177 /************************************************************************************/
178 /************************************************************************************/
185 #define SGN(a) (a>=0?1:-1)
186 
187 /************************************************************************************/
188 /************************************************************************************/
195 #define ADJUST_REAL(a) (fabs(a)<ZERO?0.0:(fabs(a-1.0)<ZERO?+1.0:(fabs(a+1.0)<ZERO?-1.0:a)))
196 
197 /************************************************************************************/
198 /************************************************************************************/
205 #define PI2PI(a) {if ((a<-M_PI-ZERO)||(a>M_PI+ZERO)) {a=fmod(a,M_2PI); while(a>M_PI) a-=M_2PI; while (a<-M_PI) a+=M_2PI;}}
206 
207 /************************************************************************************/
208 /************************************************************************************/
213 #define ROUNDUP fesetround(FE_UPWARD)
214 
219 #define ROUNDDOWN fesetround(FE_DOWNWARD)
220 
225 #define ROUNDNEAR fesetround(FE_TONEAREST)
226 
227 /************************************************************************************/
228 /************************************************************************************/
229 
237 #define INF_CUT(a) ((a<=-INF?-INF:(a>=INF)?INF:a))
238 
246 #define IS_INF(a) ((a==-INF)||(a==INF))
247 
255 #define IS_NOT_INF(a) ((a!=-INF)&&(a!=INF))
256 
267 #define INF_SCALE(s,a) (IS_INF(a)?(s<0?-a:a):(s*a))
268 
276 #define INF_EXP(a) ((a==-INF)?0:((a==INF)?INF:exp(a)))
277 
289 #define INF_PROD(a,b,d) (IS_NOT_INF(a)&&IS_NOT_INF(b)?(a*b):(IS_INF(a)&&IS_INF(b)?(a==b?a:(d?-INF:INF)):(IS_INF(a)?(b>ZERO?a:(b<-ZERO?-a:0.0)):(a>ZERO?b:(a<-ZERO?-b:0.0)))))
290 
302 #define INF_ADD(a,b,d) (IS_NOT_INF(a)&&IS_NOT_INF(b)?(a+b):(IS_INF(a)&&IS_INF(b)?(a==b?a:(d?-INF:INF)):(IS_INF(a)?a:b)))
303 
315 #define INF_SUBS(a,b,d) (IS_NOT_INF(a)&&IS_NOT_INF(b)?(a-b):(IS_INF(a)&&IS_INF(b)?(a==b?(d?-INF:INF):a):(IS_INF(a)?a:-b)))
316 
325 #define INF_POW(a,p) (IS_NOT_INF(a)?pow(a,(double)p):((a==-INF)?(((p%2)==0)?INF:-INF):INF))
326 
334 #define INF_SQRT(a) ((a==INF)?INF:(a<0.0?0.0:sqrt(a)));
335 
344 #define INF_PRINT(f,a) (a==INF?fprintf(f,"inf"):(a==-INF?fprintf(f,"-inf"):fprintf(f,"%.12g",a)))
345 
346 
352 #define ANGLE_ACCURACY 1e-4
353 
362 #define ROUND2SYMBOL(a) (fabs((a)+M_PI)<ANGLE_ACCURACY?-M_PI:(fabs((a)-M_PI)<ANGLE_ACCURACY?M_PI:(fabs((a)+M_PI_2)<ANGLE_ACCURACY?-M_PI_2:(fabs((a)-M_PI_2)<ANGLE_ACCURACY?M_PI_2:a))))
363 
376 #define SYMBOL_PRINT(f,a) (fabs((a)+M_PI)<ANGLE_ACCURACY?fprintf(f,"-PI"):(fabs((a)-M_PI)<ANGLE_ACCURACY?fprintf(f,"PI"):(fabs((a)+M_PI_2)<ANGLE_ACCURACY?fprintf(f,"-PI/2"):(fabs((a)-M_PI_2)<ANGLE_ACCURACY?fprintf(f,"PI/2"):INF_PRINT(f,a)))))
377 
378 /************************************************************************************/
379 /************************************************************************************/
385 #define NEW(_var,_n,_type) {(_var)=(_type *)malloc(sizeof(_type)*(_n)); \
386  if (!(_var)) Error("Memory allocation error");}
387 
394 #define NEWZ(_var,_n,_type) {(_var)=(_type *)calloc(_n,sizeof(_type)); \
395  if (!(_var)) Error("Memory allocation error");}
396 
404 #define MEM_EXPAND(_var,_n,_type) {(_var)=(_type *)realloc((void *)(_var),sizeof(_type)*(_n)); \
405  if (!(_var)) Error("Memory reallocation error");}
406 
414 #define MEM_DUP(_var,_n,_type) {(_n)*=2;MEM_EXPAND(_var,_n,_type);}
415 
416 /************************************************************************************/
417 /************************************************************************************/
427 #define PRINT_VARIABLE_NAME(f,name) if (name[0]=='_') fprintf(f,"%s",&(name[1])); else fprintf(f,"%s",name)
428 
429 /************************************************************************************/
430 /************************************************************************************/
435 #define NO_UINT ((unsigned int)(-1))
436 
437 /************************************************************************************/
438 /************************************************************************************/
439 
451 #define MOV_AVG_UP 0.1
452 
453 /************************************************************************************/
454 /************************************************************************************/
455 
467 #define MOV_AVG_DOWN 0.1
468 
469 
470 #endif
Error and warning functions.