defines.h File Reference

## Detailed Description

Definitions of constants and macros used in several parts of the cuik library.

geom.h

Definition in file defines.h.

## Macros

#define ZERO   1e-11
Floating point operations giving a value below this constant (in absolute value) are considered 0. More...

#define RANDOMNESS   (_DEBUG<2)
If 0 we avoid any randomness in the cuiksuite behavior. More...

#define INF   DBL_MAX
Infinite. More...

#define M_PI   3.14159265358979323846
Pi. More...

#define M_PI_2   1.57079632679489661923
Pi/2. More...

#define M_2PI   (2.0*M_PI)
2*Pi. More...

#define M_E   2.718281828459045
e. More...

#define TOPOLOGY_R   1
One of the possible topologies. More...

#define TOPOLOGY_S   2
One of the possible topologies. More...

#define MAX_INCLUDES   100
Maximum number of nested included files. More...

#define SWAP(a, b, c)   {c=a;a=b;b=c;}
Swaps two values. More...

Constant to transform from degrees to radiants. More...

Constant to transform from radiants to degrees. More...

#define SGN(a)   (a>=0?1:-1)
Returns the sign of a floating point. More...

Adjust a real to 0,1,-1, if possible. More...

#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;}}
Forces an angle go be in [-pi,pi]. More...

#define ROUNDUP   fesetround(FE_UPWARD)
Sets the floating point operations in rounding up mode. More...

#define ROUNDDOWN   fesetround(FE_DOWNWARD)
Sets the floating point operations in rounding down mode. More...

#define ROUNDNEAR   fesetround(FE_TONEAREST)
Sets the floating point operations in round near mode. More...

#define INF_CUT(a)   ((a<=-INF?-INF:(a>=INF)?INF:a))
Sets a number, without going beyond +/-inf. More...

#define IS_INF(a)   ((a==-INF)||(a==INF))
Identifies +/-inf. More...

#define IS_NOT_INF(a)   ((a!=-INF)&&(a!=INF))
Identifies not +/-inf. More...

#define INF_SCALE(s, a)   (IS_INF(a)?(s<0?-a:a):(s*a))
Scales a number, possibly inf or -inf. More...

#define INF_EXP(a)   ((a==-INF)?0:((a==INF)?INF:exp(a)))
Exponentional of a number, possibly inf or -inf. More...

#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)))))
Product of two numbers, possibly inf or -inf. More...

Adds two numbers, possibly inf or -inf. More...

#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)))
Substract two numbers, possibly inf or -inf. More...

#define INF_POW(a, p)   (IS_NOT_INF(a)?pow(a,(double)p):((a==-INF)?(((p%2)==0)?INF:-INF):INF))
Power of a number, possibly +/-inf. More...

#define INF_SQRT(a)   ((a==INF)?INF:(a<0.0?0.0:sqrt(a)));
Sqrt of a number, possibly +/-inf. More...

#define INF_PRINT(f, a)   (a==INF?fprintf(f,"inf"):(a==-INF?fprintf(f,"-inf"):fprintf(f,"%.12g",a)))
Prints a number (possibly +/-inf) to a file. More...

#define ANGLE_ACCURACY   1e-4
Accuracy for the rounding to +/-PI, +/-PI/2. More...

#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))))
Round to +/-PI, +/-PI/2. More...

#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)))))
Prints a number (possibly +/-PI, +/-PI/2, or +/-inf) to a file. More...

#define NEW(_var, _n, _type)
Allocates memory space. More...

#define NEWZ(_var, _n, _type)
Allocates and cleans memory space. More...

#define MEM_EXPAND(_var, _n, _type)
Expands a previously allocated memory space. More...

#define MEM_DUP(_var, _n, _type)   {(_n)*=2;MEM_EXPAND(_var,_n,_type);}
Duplicates a previously allocated memory space. More...

#define PRINT_VARIABLE_NAME(f, name)   if (name[0]=='_') fprintf(f,"%s",&(name[1])); else fprintf(f,"%s",name)
Prints a variable name into a file. More...

#define NO_UINT   ((unsigned int)(-1))
Used to denote an identifier that has not been initialized. More...

#define MOV_AVG_UP   0.1
Weight of new data when computing moving averages. More...

#define MOV_AVG_DOWN   0.1
Weight of new data when computing moving averages. More...

## Macro Definition Documentation

 #define ZERO   1e-11

Floating point operations giving a value below this constant (in absolute value) are considered 0.

We use 1e-11 because trigonometric operations (sin/cos/...) give an error typically around 1e-12. Moreover, we print doubles with 12 decimals and, thus the last one typically varies when performing operations. Note that 1e-11 is far below the typical precission used inside the simplex algorithms (1e-6).

No to be confused with parameter EPSILON. ZERO is used as a general threshold to round towards 0 and Epsilon is used only when passing parameters to the simplex. For a super-numerically-stable simplex EPSILON and ZERO would be the same.

Definition at line 37 of file defines.h.

 #define RANDOMNESS   (_DEBUG<2)

If set to 0 we avoid any randomness in the cuiksuite behavior. This is basically used for debug. In norma mode, the applications in the cuiksuite rely on some randomness (to select the variable to split a box, to select the split point,...). This is usefull to improve the performance in degenerate situations and it does not hinder the convergence in the usual cases. For debug purposes, though, this randomness can be quite annoying and can be deactivated here.

Right now we only use random behavior when in optimized mode.

Todo:
Remove this in the final version. This is for debug only

Definition at line 55 of file defines.h.

Referenced by BuildAtlasFromPoint().

 #define M_PI   3.14159265358979323846
 #define M_PI_2   1.57079632679489661923

Pi/2

Definition at line 92 of file defines.h.

 #define M_2PI   (2.0*M_PI)
 #define M_E   2.718281828459045

Base of the natural log.

Definition at line 109 of file defines.h.

 #define TOPOLOGY_R   1

The range of the variables is defined over the reals.

Definition at line 122 of file defines.h.

 #define TOPOLOGY_S   2

The range of the variables is defined over a circle.

IMPORTANT: Only variables with range equal (or larger) than 2*pi are actually considered to have TOPOLOGY_S. Variables defined with TOPOLOGY_S but with small ranges are actually treated as varaibles with TOPOLOGY_R.

If a variable x has TOPOLOGY_S it means that we can replace this variable by x+k*2*pi (k any integer) and the system of equations remains the same. If a variable is defined with TOPOLOGY_S but it does not fulfills the above condition an error is likely to occur.

Definition at line 139 of file defines.h.

 #define MAX_INCLUDES   100

A maximum of recursively included files to avoid infinite loops.

Definition at line 148 of file defines.h.

 #define SWAP ( a, b, c ) {c=a;a=b;b=c;}

Swaps two values using an intermediate storage.

Parameters
 a First value to swap. b Second value to swap. c Intermediate storage for the swap.

Definition at line 161 of file defines.h.

Constant to transform from degrees to radiants.

Definition at line 169 of file defines.h.

Referenced by main().

Constant to transform from radiants to degrees.

Definition at line 175 of file defines.h.

 #define SGN ( a ) (a>=0?1:-1)

Returns the sign of a floating point: -1 for negative and 1 for possitive or zero.

Parameters
 a The number to operate.

Definition at line 185 of file defines.h.

Referenced by PolytopeBoundaryPointFromExternalCornerInt().

 #define ADJUST_REAL ( a ) (fabs(a)

Adjust a real to 0,1,-1, if possible.

Parameters

Definition at line 195 of file defines.h.

 #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;}}

Forces an angle go be in [-pi,pi]. This is intended to be used with a variable as a parameter (using an expression would be ineficient).

Definition at line 205 of file defines.h.

 #define ROUNDUP   fesetround(FE_UPWARD)

Sets the floating point operations in rounding up mode.

Definition at line 213 of file defines.h.

 #define ROUNDDOWN   fesetround(FE_DOWNWARD)

Sets the floating point operations in rounding down mode.

Definition at line 219 of file defines.h.

 #define ROUNDNEAR   fesetround(FE_TONEAREST)

Sets the floating point operations in round near mode. This is the default mode.

Definition at line 225 of file defines.h.

 #define INF_CUT ( a ) ((a<=-INF?-INF:(a>=INF)?INF:a))

Sets a number, without going beyond +/-inf..

Parameters
 a The number to check.

Definition at line 237 of file defines.h.

 #define IS_INF ( a ) ((a==-INF)||(a==INF))

TRUE if the number is either inf or -inf.

Parameters
 a The number to check.

Definition at line 246 of file defines.h.

Referenced by EnlargeInterval(), IntervalCenter(), IntervalSize(), and PointInInterval().

 #define IS_NOT_INF ( a ) ((a!=-INF)&&(a!=INF))

TRUE if the number is not inf or -inf.

Parameters
 a The number to check.

Definition at line 255 of file defines.h.

Referenced by EnlargeInterval().

 #define INF_SCALE ( s, a ) (IS_INF(a)?(s<0?-a:a):(s*a))

Scales a number, possibly inf or -inf.

INF_PROD if 's' can be inf also.
Parameters
 s The scale factor (this is not +/-inf). a The number to scale.

Definition at line 267 of file defines.h.

Referenced by IntervalScale().

 #define INF_EXP ( a ) ((a==-INF)?0:((a==INF)?INF:exp(a)))

Exponentional of a number, possibly inf or -inf.

Parameters
 a The number to operate.

Definition at line 276 of file defines.h.

Referenced by IntervalExp().

 #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)))))

Product of two numbers, possibly inf or -inf.

When rounding down, INF*(-INF) is set to -INF, otherwise to INF.

Parameters
 a The first number to operate. b The second number to operate. d TRUE if rounding down.

Definition at line 289 of file defines.h.

Referenced by IntervalProduct().

 #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)))

Adds two numbers, possibly inf or -inf.

When rounding down, INF+(-INF) is set to -INF, otherwise to INF.

Parameters
 a The first number to operate. b The second number to operate. d TRUE if rounding down.

Definition at line 302 of file defines.h.

 #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)))

Substract two numbers, possibly inf or -inf.

When rounding down, INF-INF is set to -INF, otherwise to INF.

Parameters
 a The first number to operate. b The second number to operate. d TRUE if rounding down.

Definition at line 315 of file defines.h.

Referenced by IntervalSubstract().

 #define INF_POW ( a, p ) (IS_NOT_INF(a)?pow(a,(double)p):((a==-INF)?(((p%2)==0)?INF:-INF):INF))

Power of a number, possibly +/-inf.

Parameters
 a The number to operate. p The power (integer possitive).

Definition at line 325 of file defines.h.

Referenced by IntervalPow().

 #define INF_SQRT ( a ) ((a==INF)?INF:(a<0.0?0.0:sqrt(a)));

Sqrt of a number, possibly +/-inf.

Parameters
 a The number to operate.

Definition at line 334 of file defines.h.

Referenced by IntervalSqrt().

 #define INF_PRINT ( f, a ) (a==INF?fprintf(f,"inf"):(a==-INF?fprintf(f,"-inf"):fprintf(f,"%.12g",a)))

Prints a number (possibly +/-inf) to a file.

Parameters
 f The file. a The number.

Definition at line 344 of file defines.h.

Referenced by PrintInterval().

 #define ANGLE_ACCURACY   1e-4

Accuracy used when rounding values to +/-PI and +/-PI/2

Definition at line 352 of file defines.h.

 #define ROUND2SYMBOL ( a ) (fabs((a)+M_PI)

When reading values from equation files, we round them to +/-PI or to +/-PI/2 to gain accuracy. The rounding is only applied for variables that are known to be angles.

Parameters
 a The angular value to round.

Definition at line 362 of file defines.h.

 #define SYMBOL_PRINT ( f, a ) (fabs((a)+M_PI)

Prints a number (possibly +/-PI, +/-PI/2, or +/-inf) to a file. Numbers close (up to 1e-4 to +/-PI or +/-PI/2 are printed symbolically). This increases accuracy when reading these values.

This type of printing is only used for variables that are known to be angles.

Parameters
 f The file. a The angular value to print.

Definition at line 376 of file defines.h.

Referenced by PrintSymbolInterval().

 #define NEWZ ( _var, _n, _type )
Value:
{(_var)=(_type *)calloc(_n,sizeof(_type)); \
if (!(_var)) Error("Memory allocation error");}
void Error(const char *s)
General error function.
Definition: error.c:80

Allocates memory space for _n elements of type _type and assigns the pointer to _var and initializes the space to zero. If the memory can not be allocated, triggers an error.

Definition at line 394 of file defines.h.

 #define MEM_EXPAND ( _var, _n, _type )
Value:
{(_var)=(_type *)realloc((void *)(_var),sizeof(_type)*(_n)); \
if (!(_var)) Error("Memory reallocation error");}
void Error(const char *s)
General error function.
Definition: error.c:80

Expands a previously reserved memory space so that it can accomodate _n elements of type _type assigns the pointer to _var. The previously allocated space is pointed by _var. If the memory can not be expanded, triggers an error.

Definition at line 404 of file defines.h.

 #define MEM_DUP ( _var, _n, _type ) {(_n)*=2;MEM_EXPAND(_var,_n,_type);}

Dublicates a previously reserved memory space that accomodates _n elements of type _type. After the duplication, the pointer _var takes to a memory space that can accomodate 2*_n elements and the value of variable _n is also doubled.

Definition at line 414 of file defines.h.

 #define PRINT_VARIABLE_NAME ( f, name ) if (name[0]=='_') fprintf(f,"%s",&(name[1])); else fprintf(f,"%s",name)

Automatically generated variables have a name that starts with a '_'. This is done to avoid the generation of a variable with the same name of a variable defined by the user (the syntax does not allow for variables starting with a '_').
When printing the name of the variable into a file we remove the starting '_' to allow the input parser to read the output file. If this results in a duplicated variable the parser will detect it.

Definition at line 427 of file defines.h.

Referenced by main(), PrintBoxSubset(), PrintMapping(), PrintTransSeq(), PrintVariable(), and PrintVarSet().

 #define MOV_AVG_UP   0.1

Weight used for the new data when computing moving averages. In particular this constant gives the weight when increasing the average.

This is typically used to self-tune parameters.

This value must be between 0 and 1. If 0 the new data is not taken into account. If 1 only the new data is used (forgetting the previous one). A standard value for this parameter is in the range [0.01, 0.1].

Definition at line 451 of file defines.h.