//Global definitions to be used by any part of any program #ifndef INT // #include thie file at the start of every compilable (.cpp) file. Then // other #include files can assume that these definitions are already made and // need not #include this file themselves. // I. Standard C and C++ Library Definitions // ------------------------------------------ #include // C++ stream I-O #include // Debugging (assertion) macro // II. Type Definitions // --------------------- // To save horizontal space in declarations, improve program readability, // and encourage use of "const" #define INT const int #define SHORT const short #define LONG const long #define CHAR const char #define BOOL const bool #define FLOAT const float #define DOUBLE const double #define uint unsigned int #define ushort unsigned short #define ulong unsigned long #define uchar unsigned char #define UINT const uint #define USHORT const ushort #define ULONG const ulong #define UCHAR const uchar typedef int sizet; // Replaces C's conventional size_t to typedef INT SIZET; // avoid clashes with unsigned // III Constants // -------------- DOUBLE PI = 3.1415926535897932385; DOUBLE E = 2.7182818284590452354; // III. Generic Functions // --------------------- #define tpl1 template inline /* Local macros for */ #define tpl2 template inline /* template functions */ // Utility and simple arithmetic // ----------------------------- tpl1 T abs (T X) {return X < 0 ? -X : X; } tpl2 T1 min (T1 X, T2 Y) {return X < (T1) Y ? X : Y; } tpl2 T1 max (T1 X, T2 Y) {return X > (T1) Y ? X : Y; } tpl1 short sign (T X) {return X < 0 ? -1 : 1;} tpl2 void swap (T1& X, T2& Y){T1 tempo=X; X=Y; Y=tempo;} // Derived relational operators, so that classes need only override // == and < as primitives. tpl2 bool operator!= (const T1 ls, const T2 rs){return ! (ls == rs);} tpl2 bool operator> (const T1 ls, const T2 rs){return (rs < ls);} tpl2 bool operator<= (const T1 ls, const T2 rs){return ! (ls > rs);} tpl2 bool operator>= (const T1 ls, const T2 rs){return (rs <= ls);} #undef tpl1 #undef tpl2 #endif