Created
October 24, 2017 15:13
-
-
Save YulongNiu/c0f9ddb8b8ef6182f83958130fbe0830 to your computer and use it in GitHub Desktop.
Test the maximum and minimum int value in C++11
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <limits> | |
using namespace std; | |
int main() { | |
int a = numeric_limits<int>::min(); | |
int b = numeric_limits<int>::max(); | |
// test IEEE 754 | |
cout << numeric_limits<double>::is_iec559 << "\n"; | |
cout << numeric_limits<float>::is_iec559 << "\n"; | |
// test min and max | |
cout << "min is " << a << " and max is " << b << "\n"; | |
// cross limits | |
for (int i = 0; i < 10; ++i) { | |
cout << "test " << i << " cross min is " << a - 1 << " and cross max is " << b + 1 << "\n"; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment