23
#define MAX(a,b) ((a)>(b) ? (a) : (b))
24
#define MIN(a,b) ((a)<(b) ? (a) : (b))
28
#define ABS(a) ((a)>=0 ? (a) : (-(a)))
31
/********* TOGGLE_BOOL(boolean) : toggles values of 'boolean' ******/
33
#define TOGGLE_BOOL(a) ((a)=1-(a))
37
/******************** bit comparisons and operations ***************/
39
#define TEST_BIT( x, b ) (((x) & (1<<(b))) != 0 )
40
#define SET_BIT( x, b ) ((x) |= (1 << (b)))
41
#define CLEAR_BIT( x, b ) ((x) &= ~(1 << (b)))
42
#define TOGGLE_BIT( x, b ) ((TEST_BIT(x,b)) ?(CLEAR_BIT(x,b)):(SET_BIT(x,b)))
46
#define TEST_AND( a, b ) ((a&b)==b)
51
#define M_PI 3.141592654
54
typedef char String[81];
57
/*********** flush the stdout and stderr output streams *************/
59
#define flushout fflush(stdout)
60
#define flusherr fflush(stderr)
64
/********** Debugging functions *************************************/
66
#define error_return( c ); {fprintf(stderr,c);return;}
70
/************************* floating-point random ********************/
72
#define randf() ((float) rand() / (float)RAND_MAX )
76
#define SIGN(x) ((x)>=0 ? 1 : -1)
80
/****************** conversion between degrees and radians **********/
82
#define DEG2RAD(x) ((x)/180.0*M_PI)
83
#define RAD2DEG(x) ((x)/M_PI*180.0)
87
/***************** clamp a value to some fixed interval *************/
89
#define CLAMP(x,lo,hi) {if ((x) < (lo)) {(x)=(lo);} else if((x) > (hi)) {(x)=(hi);}}
94
/************ check if a value lies within a closed interval *********/
96
#define IN_BOUNDS( x, lo, hi ) ( (x) >= (lo) AND (x) <= (hi) )
100
/************ check if a 2D point lies within a 2D box ***************/
102
#define PT_IN_BOX( x, y, lo_x, hi_x, lo_y, hi_y ) \
103
( IN_BOUNDS(x,lo_x,hi_x) AND IN_BOUNDS(y,lo_y,hi_y) )
106
/****** check if value lies on proper side of another value *****/
107
/*** if side is positive => proper side is positive, else negative **/
108
#ifndef CHECK_PROPER_SIDE
109
#define CHECK_PROPER_SIDE(x,val,side) ((side) > 0 ? (x) > (val) : (x) < (val))
113
/***** Small value when we want to do a comparison to 'close to zero' *****/
119
/******************* swap two values, using a temp variable *********/
121
#define SWAP2(a,b,t) {t=a;a=b;b=t;}
124
#define VEC3_TO_ARRAY(v,a) a[0]=v[0], a[1]=v[1], a[2]=v[2]
126
#endif /* _STDINC_H_ */