std::numeric_limits
STD::数字[医]限值
Defined in header | | |
---|---|---|
template< class T > class numeric_limits; | | |
大numeric_limits类模板提供了一种标准的方法来查询算术类型%28的各种属性。类型的最大可能值。int是std::numeric_limits<int>::max()29%。
这些信息是通过numeric_limits
模板。标准库为所有算术类型提供了可用的专门化:
Defined in header | | |
---|---|---|
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<char16_t>; // C++11 feature template<> class numeric_limits<char32_t>; // C++11 feature 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>; template<> class numeric_limits<unsigned long long>; template<> class numeric_limits<float>; template<> class numeric_limits<double>; template<> class numeric_limits<long double>; | | |
此外,每种算术类型的每个cv限定版本都存在一个专门化,与不合格的专门化相同。std::numeric_limits<const int>,,,std::numeric_limits<volatile int>,和std::numeric_limits<const volatile int>提供,并相当于std::numeric_limits<int>...
标准库类型,它是算术类型%28的别名,如std::size_t
或std::streamsize
5月29日%亦会与std::numeric_limits
类型特征。
非算术标准类型,如std::complex<T>或std::nullptr_t,没有专门性。
实现可以提供以下方面的专门化:std::numeric_limits对于实现-特定类型:例如gcc提供std::numeric_limits<__int128>非标准图书馆可添加专门化为图书馆提供的类型,例如。OpenEXR提供std::numeric_limits<half>16位浮点类型。
模板参数
T | - | a type to retrieve numeric properties for |
---|
成员常数
is_specialized static | identifies types for which std::numeric_limits is specialized (public static member constant) |
---|---|
is_signed static | identifies signed types (public static member constant) |
is_integer static | identifies integer types (public static member constant) |
is_exact static | identifies exact types (public static member constant) |
has_infinity static | identifies floating-point types that can represent the special value "positive infinity" (public static member constant) |
has_quiet_NaN static | identifies floating-point types that can represent the special value "quiet not-a-number" (NaN) (public static member constant) |
has_signaling_NaN static | identifies floating-point types that can represent the special value "signaling not-a-number" (NaN) (public static member constant) |
has_denorm static | identifies the denormalization style used by the floating-point type (public static member constant) |
has_denorm_loss static | identifies the floating-point types that detect loss of precision as denormalization loss rather than inexact result (public static member constant) |
round_style static | identifies the rounding style used by the type (public static member constant) |
is_iec559 static | identifies the IEC 559/IEEE 754 floating-point types (public static member constant) |
is_bounded static | identifies types that represent a finite set of values (public static member constant) |
is_modulo static | identifies types that handle overflows with modulo arithmetic (public static member constant) |
digits static | number of radix digits that can be represented without change (public static member constant) |
digits10 static | number of decimal digits that can be represented without change (public static member constant) |
max_digits10 static | number of decimal digits necessary to differentiate all values of this type (public static member constant) |
radix static | the radix or integer base used by the representation of the given type (public static member constant) |
min_exponent static | one more than the smallest negative power of the radix that is a valid normalized floating-point value (public static member constant) |
min_exponent10 static | the smallest negative power of ten that is a valid normalized floating-point value (public static member constant) |
max_exponent static | one more than the largest integer power of the radix that is a valid finite floating-point value (public static member constant) |
max_exponent10 static | the largest integer power of 10 that is a valid finite floating-point value (public static member constant) |
traps static | identifies types which can cause arithmetic operations to trap (public static member constant) |
tinyness_before static | identifies floating-point types that detect tinyness before rounding (public static member constant) |
成员函数
min static | returns the smallest finite value of the given type (public static member function) |
---|---|
lowest static | returns the lowest finite value of the given type (public static member function) |
max static | returns the largest finite value of the given type (public static member function) |
epsilon static | returns the difference between 1.0 and the next representable value of the given floating-point type (public static member function) |
round_error static | returns the maximum rounding error of the given floating-point type (public static member function) |
infinity static | returns the positive infinity value of the given floating-point type (public static member function) |
quiet_NaN static | returns a quiet NaN value of the given floating-point type (public static member function) |
signaling_NaN static | returns a signaling NaN value of the given floating-point type (public static member function) |
denorm_min static | returns the smallest positive subnormal value of the given floating-point type (public static member function) |
帮助者类
float_round_style | indicates floating-point rounding modes (enum) |
---|---|
float_denorm_style | indicates floating-point denormalization modes (enum) |
与C库宏常数的关系
Specialization | Members |
---|---|
min() | lowest()(C++11) |
numeric_limits< bool > | |
numeric_limits< char > | CHAR_MIN |
numeric_limits< signed char > | SCHAR_MIN |
numeric_limits< unsigned char > | 0 |
numeric_limits< wchar_t > | WCHAR_MIN |
numeric_limits< char16_t > | 0 |
numeric_limits< char32_t > | 0 |
numeric_limits< short > | SHRT_MIN |
numeric_limits< signed short > | |
numeric_limits< unsigned short > | 0 |
numeric_limits< int > | INT_MIN |
numeric_limits< signed int > | |
numeric_limits< unsigned int > | 0 |
numeric_limits< long > | LONG_MIN |
numeric_limits< signed long > | |
numeric_limits< unsigned long > | 0 |
numeric_limits< long long > | LLONG_MIN |
numeric_limits< signed long long > | |
numeric_limits< unsigned long long > | 0 |
numeric_limits< float > | FLT_MIN |
numeric_limits< double > | DBL_MIN |
numeric_limits< long double > | LDBL_MIN |
例
二次
#include <limits>
#include <iostream>
int main()
{
std::cout << "type\tlowest\thighest\n";
std::cout << "int\t"
<< std::numeric_limits<int>::lowest() << '\t'
<< std::numeric_limits<int>::max() << '\n';
std::cout << "float\t"
<< std::numeric_limits<float>::lowest() << '\t'
<< std::numeric_limits<float>::max() << '\n';
std::cout << "double\t"
<< std::numeric_limits<double>::lowest() << '\t'
<< std::numeric_limits<double>::max() << '\n';
}
二次
可能的产出:
二次
type lowest highest
int -2147483648 2147483647
float -3.40282e+38 3.40282e+38
double -1.79769e+308 1.79769e+308
二次
另见
- 算术类型
- C++型系统概述
- 类型支持%28基本类型,RTTI,类型性状%29
© cppreference.com
在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。