// preproc.cc (<-- Euler.cc) // Demonstration of preprocessing directives // Pre: include file #include #include //------------------------------------------------------------- // Pre: Alternative - Check whether M_PI is not defined #ifndef M_PI // Pre: Define M_PI in that case #define M_PI 3.14159 // Pre: else-branch of alternative may follow #else // // Pre: End of alternative #endif //------------------------------------------------------------- // Pre: Define your own variables #define MY_DEBUG // Pre: Undefine your own variable //#undef MY_DEBUG // Pre: Define variable #define SEE_PI 5 //------------------------------------------------------------- // Pre: Define your own macro #define MAX(x,y) (x > y ? x : y) //------------------------------------------------------------- int main() { float e1; long long int i,n,m,j; n = 1000; m = 100000; for (i=1; i<=n; i++) { j = i*m; e1 = pow(1.0+1.0/j,double(j)); // Pre: Use your own variable #ifdef MY_DEBUG cout << "e - e1 = " << exp(1) - e1 << endl; #endif } cout << endl << "e = " << exp(1) << endl; // M_E is the predefined Euler number (/usr/include/math.h) cout << endl << "e = " << M_E - exp(1) << endl; // Check the value of preprocessor variable #if (SEE_PI<5) // M_PI is the predefined PI number (/usr/include/math.h) cout << M_PI << " " <