It’s been a really long time since I last wrote a blog. It’s like… more than a year?
And thanks to the super easy college entrance exam, I am able to study in HKUST now.
And I think it’s time to continue writing blogs to mark down some things in my daily life and especially in the computer science study. I decide to use English because all of my courses are given in english :D.
Back to today, I toke the first lecture of COMP2012H this morning and I have to say that Dr. Desmond is a great instructor. The class was so interesting. And now I would like to write something new to me.
We can use numeric_limits::min() and numeric_limits::max() to find the lower bound and upper bound of TYPE in C++.
Like what I show below.
#include
#include // Library limits - For numeric_limits::min() and numeric_limits::max()
using namespace std;
int main()
{
// Value range of short
cout << "Lower bound of short: " << numeric_limits<short>::min() << endl;
cout << "Upper bound of short: " << numeric_limits<short>::max() << endl;
// Value range of int
cout << "Lower bound of int: " << numeric_limits<int>::min() << endl;
cout << "Upper bound of int: " << numeric_limits<int>::max() << endl;
// Value range of long
cout << "Lower bound of long: " << numeric_limits<long>::min() << endl;
cout << "Upper bound of long: " << numeric_limits<long>::max() << endl;
// Value range of long long
cout << "Lower bound of long long: " << numeric_limits<long long>::min() << endl;
cout << "Upper bound of long long: " << numeric_limits<long long>::max() << endl;
// Value range of float
cout << "Lower bound of float: " << numeric_limits<float>::min() << endl;
cout << "Upper bound of float: " << numeric_limits<float>::max() << endl;
// Value range of double
cout << "Lower bound of double: " << numeric_limits<double>::min() << endl;
cout << "Upper bound of double: " << numeric_limits<double>::max() << endl;
// Value range of long double
cout << "Lower bound of long double: " << numeric_limits<long double>::min() << endl;
cout << "Upper bound of long double: " << numeric_limits<long double>::max() << endl;
// Value range of bool
cout << "Lower bound of bool: " << numeric_limits<bool>::min() << endl;
cout << "Upper bound of bool: " << numeric_limits<bool>::max() << endl;
return 0; // The program is executed successfully.
}