Skip to content

Instantly share code, notes, and snippets.

@YulongNiu
Created October 24, 2017 15:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save YulongNiu/c0f9ddb8b8ef6182f83958130fbe0830 to your computer and use it in GitHub Desktop.
Save YulongNiu/c0f9ddb8b8ef6182f83958130fbe0830 to your computer and use it in GitHub Desktop.
Test the maximum and minimum int value in C++11
#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