//============================================================================ // Author : Svenson Han Gothel and Sven Gothel // Version : 0.1 // Copyright : MIT // Description : C++ Lesson 0.2a Applied arithmetic using C++ //============================================================================ #include #include #include #include /** * Lesson 0.2 * * Implementing simple arithmetic functionality */ struct DivisionResult { int factor; int remainder; }; DivisionResult divide(const int z, const int n) { int r=0; int c=z; while ( c >= n ) { c -= n; // c = c - n; ++r; // r = r + 1; } return DivisionResult { .factor=r, .remainder=c }; } int mult(const int a, const int b) { int r=0; for (int i=0; i 1 ) { // v = v - 1; // r = r * v; r *= --v; } return r; } float machineEpsilon() { const float one(1); const float two(2); float x = 1; float res; // float t; int i=0; do { res = x; x = x / two; // t = one + x; // fprintf(stderr, "%3d: %.48f -> %.48f, %.48f\n", i, res, x, t); // std::cerr << i << ": " << res << " -> " << x << std::endl; ++i; } while ( one + x > one ); (void)i; return res; } void test_limits() { unsigned int i = std::numeric_limits::max() - 10; do { fprintf(stderr, "%u, bytes %zu\n", i, sizeof(i)); if( i == std::numeric_limits::max() ) { break; // end outter loop } ++i; } while( true ); } int main(int argc, const char* argv[]) { { // loop through all program invocation arguments and print them for(int i=0; i