std::numeric_limits
Defined in header <limits> | | |
---|---|---|
template< class T > class numeric_limits; | | |
大numeric_limits
类模板提供了一种标准的方法来查询算术类型%28的各种属性。类型的最大可能值。int
是std::numeric_limits<int>::max()
29%。
这些信息是通过numeric_limits
模板。标准库为所有算术类型提供了可用的专门化:
Defined in header <limits> | | |
---|---|---|
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
,没有专门性。
模板参数
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) | max() | epsilon() | digits | digits10 | min_exponent | min_exponent10 | max_exponent | max_exponent10 | radix | |
numeric_limits< bool > | | | | | | | | | | | 2 |
numeric_limits< char > | CHAR_MIN | CHAR_MIN | CHAR_MAX | | | | | | | | 2 |
numeric_limits< signed char > | SCHAR_MIN | SCHAR_MIN | SCHAR_MAX | | | | | | | | 2 |
numeric_limits< unsigned char > | 0 | 0 | UCHAR_MAX | | | | | | | | 2 |
numeric_limits< wchar_t > | WCHAR_MIN | WCHAR_MIN | WCHAR_MAX | | | | | | | | 2 |
numeric_limits< char16_t > | 0 | 0 | UINT_LEAST16_MAX | | | | | | | | 2 |
numeric_limits< char32_t > | 0 | 0 | UINT_LEAST32_MAX | | | | | | | | 2 |
numeric_limits< short > | SHRT_MIN | SHRT_MIN | SHRT_MAX | | | | | | | | 2 |
numeric_limits< signed short > | | | | | | | | ||||
numeric_limits< unsigned short > | 0 | 0 | USHRT_MAX | | | | | | | | 2 |
numeric_limits< int > | INT_MIN | INT_MIN | INT_MAX | | | | | | | | 2 |
numeric_limits< signed int > | | | | | | | | ||||
numeric_limits< unsigned int > | 0 | 0 | UINT_MAX | | | | | | | | 2 |
numeric_limits< long > | LONG_MIN | LONG_MIN | LONG_MAX | | | | | | | | 2 |
numeric_limits< signed long > | | | | | | | |||||
numeric_limits< unsigned long > | 0 | 0 | ULONG_MAX | | | | | | | | 2 |
numeric_limits< long long > | LLONG_MIN | LLONG_MIN | LLONG_MAX | | | | | | | | 2 |
numeric_limits< signed long long > | | | | | | | | ||||
numeric_limits< unsigned long long > | 0 | 0 | ULLONG_MAX | | | | | | | | 2 |
numeric_limits< float > | FLT_MIN | -FLT_MAX | FLT_MAX | FLT_EPSILON | FLT_MANT_DIG | FLT_DIG | FLT_MIN_EXP | FLT_MIN_10_EXP | FLT_MAX_EXP | FLT_MAX_10_EXP | FLT_RADIX |
numeric_limits< double > | DBL_MIN | -DBL_MAX | DBL_MAX | DBL_EPSILON | DBL_MANT_DIG | DBL_DIG | DBL_MIN_EXP | DBL_MIN_10_EXP | DBL_MAX_EXP | DBL_MAX_10_EXP | FLT_RADIX |
numeric_limits< long double > | LDBL_MIN | -LDBL_MAX | LDBL_MAX | LDBL_EPSILON | LDBL_MANT_DIG | LDBL_DIG | LDBL_MIN_EXP | LDBL_MIN_10_EXP | LDBL_MAX_EXP | LDBL_MAX_10_EXP | FLT_RADIX |
例
二次
#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。
本文档系腾讯云开发者社区成员共同维护,如有问题请联系 cloudcommunity@tencent.com