#include <iostream>
#include <limits>
using namespace std;
int main()
{
//print maximum of various types
cout << "Maximum values :\n";
cout << "------------------\n";
cout << "short : " << numeric_limits<short>::max() << endl;
cout << "int : " << numeric_limits<int>::max() << endl;
cout << "long : " << numeric_limits<long>::max() << endl;
cout << "float : " << numeric_limits<float>::max() << endl;
cout << "double : " << numeric_limits<double>::max() << endl;
//print minimum of various types
cout << "\n";
cout << "Minimum Values: \n";
cout << "------------------\n";
cout << "short : " << numeric_limits<short>::min() << endl;
cout << "int : " << numeric_limits<int>::min() << endl;
cout << "long : " << numeric_limits<long>::min() << endl;
cout << "float : " << numeric_limits<float>::min() << endl;
cout << "double : " << numeric_limits<double>::min() << endl;
//
return 0;
}
Please Make a Note is a collection of science & technology tips and derivations that will make it easier for research scientists & engineers to perform the various tasks they are faced with. These notes cover a wide range of scientific topics, software, media, and data analysis utilities.
Pages
▼
Friday, July 23, 2010
Numeric Limits in C++
You can use the "limits" class template to obtain machine specific numeric limits. Here's a sample code:
No comments:
Post a Comment