Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _USE_MATH_DEFINES
- #include <cmath>
- #include <cstdio>
- #include <cstdlib>
- #include <limits>
- #include <cfloat>
- #include <climits>
- #include <typeinfo>
- int main(int argc, char* argv[]) {
- printf("Different numeric types and it's output:\n");
- printf("int(%%d): %d\n", 42);
- printf("long long int(%%lld): %lld\n", 42LL);
- printf("unsigned int(%%u): %u\n", 42u);
- printf("float(%%f): %f\n", 3.14F);
- printf("double(%%lf): %lf\n", 3.14);
- printf("long double(%%Lf): %Lf\n", 3.14L);
- printf("double(%%lE): %lE //Scientific format\n", 3.14);
- printf("\n\n");
- printf("sizeof() & typeid():\n");
- printf("sizeof(int) = %u\n", sizeof(int));
- int i;
- printf("sizeof(i) = %u\n", sizeof(i));
- printf("typeid(i).name() = %s\n", typeid(i).name());
- printf("typeid(10u + 5).name() = %s\n", typeid(10u + 5).name());
- printf("\n\n");
- printf("cmath demo:\n");
- printf("sqrt(%lf) = %lf\n", 3.0, sqrt(3.0));
- printf("pi = %lf\n", M_PI);
- printf("\n\n");
- printf("Infinity, NaN and overflow:\n");
- printf("+INF = %lf\n", std::numeric_limits<double>::infinity());
- printf("NaN = %lf\n", std::numeric_limits<double>::quiet_NaN());
- printf("sqrt(-1) = %lf //It's also NaN\n", sqrt(-1.0));
- printf("_isnan(sqrt(-1)) = %d\n", _isnan(sqrt(-1.0)));
- printf("max(double) = %lf\n", std::numeric_limits<double>::max());
- printf("max(double) = %lf\n", DBL_MAX);
- printf("And in scientific format max(double) = %lE\n", DBL_MAX);
- printf("\n");
- printf("max(int) = %d\n", INT_MAX);
- printf("max(int) = %d\n", std::numeric_limits<int>::max());
- printf("\n\n");
- printf("Integral overflow demo:\n");
- printf("max(int) + 1 = %d\n", std::numeric_limits<int>::max() + 1);
- printf("\n");
- printf("Floating point overflow demo:\n");
- printf("max(double) * 2.0 = %lf\n", std::numeric_limits<double>::max() * 2.0);
- printf("\n");
- printf("Lack of precision in f.p. operations:\n");
- printf("max(double) + 1 = %lf\n", std::numeric_limits<double>::max() + 1);
- system("pause");
- return 0;
- }
- /*Output
- Different numeric types and it's output:
- int(%d): 42
- long long int(%lld): 42
- unsigned int(%u): 42
- float(%f): 3.140000
- double(%lf): 3.140000
- long double(%Lf): 3.140000
- double(%lE): 3.140000E+000 //Scientific format
- sizeof() & typeid():
- sizeof(int) = 4
- sizeof(i) = 4
- typeid(i).name() = int
- typeid(10u + 5).name() = unsigned int
- cmath demo:
- sqrt(3.000000) = 1.732051
- pi = 3.141593
- Infinity, NaN and overflow:
- +INF = 1.#INF00
- NaN = 1.#QNAN0
- sqrt(-1) = -1.#IND00 //It's also NaN
- _isnan(sqrt(-1)) = 1
- max(double) = 179769313486231570000000000000000000000000000000000000000000000000
- 00000000000000000000000000000000000000000000000000000000000000000000000000000000
- 00000000000000000000000000000000000000000000000000000000000000000000000000000000
- 00000000000000000000000000000000000000000000000000000000000000000000000000000000
- 000.000000
- max(double) = 179769313486231570000000000000000000000000000000000000000000000000
- 00000000000000000000000000000000000000000000000000000000000000000000000000000000
- 00000000000000000000000000000000000000000000000000000000000000000000000000000000
- 00000000000000000000000000000000000000000000000000000000000000000000000000000000
- 000.000000
- And in scientific format max(double) = 1.797693E+308
- max(int) = 2147483647
- max(int) = 2147483647
- Integral overflow demo:
- max(int) + 1 = -2147483648
- Floating point overflow demo:
- max(double) * 2.0 = 1.#INF00
- Lack of precision in f.p. operations:
- max(double) + 1 = 17976931348623157000000000000000000000000000000000000000000000
- 00000000000000000000000000000000000000000000000000000000000000000000000000000000
- 00000000000000000000000000000000000000000000000000000000000000000000000000000000
- 00000000000000000000000000000000000000000000000000000000000000000000000000000000
- 0000000.000000
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement