Section
std::numeric_limits
The std::numeric_limits class template provides a standardized way to query various properties of arithmetic types (e.g. the largest possible value for type int is std::numeric_limits
# Declarations
template< class T > class numeric_limits;
# Example
#include <iostream>
#include <limits>
int main()
{
std::cout << "type\t│ lowest()\t│ min()\t\t│ max()\n"
<< "bool\t│ "
<< std::numeric_limits<bool>::lowest() << "\t\t│ "
<< std::numeric_limits<bool>::min() << "\t\t│ "
<< std::numeric_limits<bool>::max() << '\n'
<< "uchar\t│ "
<< +std::numeric_limits<unsigned char>::lowest() << "\t\t│ "
<< +std::numeric_limits<unsigned char>::min() << "\t\t│ "
<< +std::numeric_limits<unsigned char>::max() << '\n'
<< "int\t│ "
<< std::numeric_limits<int>::lowest() << "\t│ "
<< std::numeric_limits<int>::min() << "\t│ "
<< std::numeric_limits<int>::max() << '\n'
<< "float\t│ "
<< std::numeric_limits<float>::lowest() << "\t│ "
<< std::numeric_limits<float>::min() << "\t│ "
<< std::numeric_limits<float>::max() << '\n'
<< "double\t│ "
<< std::numeric_limits<double>::lowest() << "\t│ "
<< std::numeric_limits<double>::min() << "\t│ "
<< std::numeric_limits<double>::max() << '\n';
}
# Defect reports
| DR | Applied to | Behavior as published | Correct behavior |
|---|---|---|---|
| LWG 201 | C++98 | specializations for all fundamental types need to be provided | excluded non-arithmetic types |
| LWG 559 | C++98 | it was unclear whether the std::numeric_limitsspecialization for a cv-qualified type behaves as the same asthe corresponding specialization for the cv-unqualified type | they have thesame behavior |