
#ifndef PI
#define PI 3.14159265358979323846
#endif

#ifndef NULL
#define NULL ((void*)0)
#endif
 
#ifndef TRUE
#define TRUE  (1)
#endif
 
#ifndef FALSE
#define FALSE (0)
#endif

#define ROUND(x)            (x>0)?((int)(x+0.5)):((int)(x-0.5))
/* math.h */
#define ROUND2(v,m)         (((v) < 0.0) ? ((ceil((v) / (m) - 0.5)) * (m)) : ((floor((v) / (m) + 0.5)) * (m)))

#define ABS(x)              (x>0)? x:(-x)
#define SGN(x)              (x>0)? 1:(-1)
#define SGN2(x)             (x==0)? 0:(x>0 ? 1:(-1))

#define MIN(x,y)            (x>y)? y:x
#define MAX(x,y)            (x>y)? x:y

#define MIN3(a,b,c)         ((a)<=(b) ? (a)<=(c)?(a):(c) : (b)<=(c)?(b):(c) )
#define MAX3(a,b,c)         ((a)>=(b) ? (a)>=(c)?(a):(c) : (b)>=(c)?(b):(c) )
#define BETWEEN(a,b,c)      ((a)<=(b) and (b)<=(c))

#define IMAX(a,b)           ((a)>(b) ? (0) : (1))
#define IMIN(a,b)           ((a)<(b) ? (0) : (1))

#define TRACE(var,fmt)      printf("TRACE: " #var " = " #fmt "\n", var)
/* DEBUG("%d\n", var) */
#define DEBUG               printf("DEBUG: \"%s\", row %d: ", __FILE__, __LINE__), printf
#define ASSERT(f)           ((f) ? (void)0 : printf("Assertion " #f " failed file %s line %d\n",__FILE__, __LINE__))

#define SIZEOF(array)       ((int)(sizeof array / sizeof array[0]))
#define ENDOF(array)        (&array[SIZEOF(array)])
#define ISWHITE(c)          ((c) == ' ' || (c) == '\t')

#define TEST_BIT(x,b)       (((x) & (1<<(b))) != 0 )
#define SET_BIT(x,b)        ((x) |= (1 << (b)))
#define CLEAR_BIT(x,b)      ((x) &= ~(1 << (b)))
#define TOGGLE_BIT(x,b)     ((TEST_BIT(x,b))?(CLEAR_BIT(x,b)):(SET_BIT(x,b)))
#define ROL(x,n)            ((x) << (n) | (x) >> (sizeof(x) * 8 - (n)))
#define ROR(x,n)            ((x) >> (n) | (x) << (sizeof(x) * 8 - (n)))

#define DEG2RAD(x)          ((x)/180.0*PI)
#define RAD2DEG(x)          ((x)/PI*180.0)

#define CLAMP(x,lo,hi)      {if ((x) < (lo)) {(x)=(lo);} else if((x) > (hi)){(x)=(hi);}}
#define ALIGN(x,n)          (((x) + (n) - 1) & ~((n) - 1))
#define MAX_UVALUE(type)    ((type)~(type)0)

/* 25.11.2007 */


