template< class T > class 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<int>::max()).
This information is provided via specializations of the std::numeric_limits
template. The standard library makes available specializations for all arithmetic types (only lists the specializations for cv-unqualified arithmetic types):
template<> class numeric_limits<bool>;
template<> class numeric_limits<char>;
template<> class numeric_limits<signed char>;
template<> class numeric_limits<unsigned char>;
template<> class numeric_limits<wchar_t>;
template<> class numeric_limits<char8_t>;
(since C++20)template<> class numeric_limits<char16_t>;
(since C++11)template<> class numeric_limits<char32_t>;
(since C++11)template<> class numeric_limits<short>;
template<> class numeric_limits<unsigned short>;
template<> class numeric_limits<int>;
template<> class numeric_limits<unsigned int>;
template<> class numeric_limits<long>;
template<> class numeric_limits<unsigned long>;
template<> class numeric_limits<long long>;
(since C++11)template<> class numeric_limits<unsigned long long>;
(since C++11)template<> class numeric_limits<float>;
template<> class numeric_limits<double>;
template<> class numeric_limits<long double>;
The value of each member of a specialization of std::numeric_limits
on a cv-qualified type cv T
is equal to the value of the corresponding member of the specialization on the unqualified type T
. For example, std::numeric_limits<int>::digits is equal to std::numeric_limits<const int>::digits.
Aliases of arithmetic types (such as std::size_t or std::streamsize) may also be examined with the std::numeric_limits
type traits.
Non-arithmetic standard types, such as std::complex<T> or std::nullptr_t, do not have specializations.
If the implementation defines any integer-class types, specializations of std::numeric_limits
must also be provided for them.
Implementations may provide specializations of std::numeric_limits
for implementation-specific types: e.g. GCC provides std::numeric_limits<__int128>
. Non-standard libraries may add specializations for library-provided types, e.g. OpenEXR provides std::numeric_limits<half>
for a 16-bit floating-point type.
radix
digits that can be represented without change
1.0
and the next representable value of the given floating-point type
#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'; }
Possible output:
type â lowest() â min() â max() bool â 0 â 0 â 1 uchar â 0 â 0 â 255 int â -2147483648 â -2147483648 â 2147483647 float â -3.40282e+38 â 1.17549e-38 â 3.40282e+38 double â -1.79769e+308 â 2.22507e-308 â 1.79769e+308[edit] Defect reports
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
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 thestd::numeric_limits
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4