简介
它是一种数字限制类型,它提供有关库编译的特定平台中算术类型(整数或浮点)属性的信息.
声明
以下是std :: numeric_limits的声明.
templatenumeric_limits;
C ++ 11
templatenumeric_limits;
参数
T : 它是一种类.
示例
在下面的示例中,对于std :: numeric_limits.
#include#include int main() { std::cout << "type\tlowest type\thighest type\n"; std::cout << "int\t" << std::numeric_limits ::lowest() << '\t' << std::numeric_limits ::max() << '\n'; std::cout << "float\t" << std::numeric_limits ::lowest() << '\t' << std::numeric_limits ::max() << '\n'; std::cout << "double\t" << std::numeric_limits ::lowest() << '\t' << std::numeric_limits ::max() << '\n';}
示例输出应该是这样的 :
typelowest typehighest typeint-21474836482147483647float-3.40282e+383.40282e+38double-1.79769e+3081.79769e+308
模板实例化
C ++ 98的基本算术类型应该是这样的 :
基本算术类型 | |
---|---|
整数类型 | bool |
char | |
wchar_t | |
signed char | |
short int | |
int | |
long int | |
unsigned char | |
unsigned short int | |
unsigned int | |
unsigned long int | |
浮点类型 | float |
double | |
long double |
C的基本算术类型++ 11应该是这样的 :
基本算术类型 | |
---|---|
整数类型 | bool |
char | |
char16_t | |
char32_t | |
wchar_t | |
signed char | |
short int | |
int | |
long int | |
long long int | |
unsigned char | |
unsigned short int | |
unsigned int | |
unsigned long int | |
unsigned long long int | |
浮点类型 | float |
double | |
long double |
成员
member | type | property |
---|---|---|
bool | true for所有(即专用的那些).和所有其他类型的 false . | |
这是一个最小有限值. 浮动具有非规范化的类型(可变指数位数):最小正标准化值. 等效于,,,,,,, ,或 | ||
这是一个最大有限值. 相当于,,,,,,,,,,,,,,或,具体取决于类型. | ||
这是一个最小有限值.(自C ++ 11起) 对于整数类型:与相同. 对于浮点类型:依赖于实现;通常,. | ||
它适用于整数类型:非符号位数( 对于浮动类型:尾数中的位数(在base中)(相当于,或). | ||
int | 这是一个位数(以十进制为基数),可以表示没有变化. 对于浮动类型,等效于,或. | |
int | 这是确保数字所需的位数(以十进制为单位)不同的值总是有区别的. | |
bool | true 如果type是签名. | |
bool | true 如果type是整数. | |
bool | true 如果类型使用确切的表示. | |
int | 它适用于整数类型:表示的基础. 对于浮动类型:表示的指数的基数(相当于). | |
它是一个机器epsilon(1和最小值之间的差值可以表示). 对于浮动类型,等效于,或. | ||
衡量最大舍入误差. | ||
int | 这是一个最小负整数值,使被提升到 相当于 | |
int | 这是一个最小的负整数值,使10提升到那个幂生成一个标准化的浮点数. 等效于,或用于浮动类型. | |
int | 这是一个最大整数值,使raise to 相当于 | |
int | 这是一个最大整数值,使得10倍于该功率产生标准化有限浮点数. 等效于,或用于浮动类型. | |
bool | true 如果类型有正无穷大的表示. | |
bool | true 如果类型表示安静(非信令)"非数字". | |
bool | true 如果类型有一个信号"Not-a-Number"的表示. | |
这是一个非规范化的值(具有可变数量的指数位的表示).一个类型可以具有以下任何枚举值 : ,如果它不允许非规范化值. ,如果它允许非规范化值. ,如果在编译时不确定. | ||
bool | true if a 精度损失被检测为非规范化损失,而不是不精确的结果. | |
它代表正无穷大,如果有的话. | ||
表示安静(非信号)"Not-a - ",如果有的话. | ||
它代表发出信号"Not-a-Number",如果有的话./td> | ||
最小正非规范化值. 适用于类型不允许非规范化值:与 | ||
bool |
IEC-559类型总是有,和设置为 | |
bool | true if set由类型表示的值是有限的. | |
bool | true 如果类型如果可以添加两个正数并且结果包含到第三个更小的数字,那么类型是 modulo . | |
bool | true 如果陷阱是为类型实现. | |
bool | true if tinyness is在舍入之前检测到. | |
这是一种舍入样式.类型可以包含以下任何枚举值 : ,如果它向零舍入. ,如果它舍入到最近可表示的值. ,如果它向无穷大舍入. ,如果如果在编译时舍入样式是不确定的,那么它向负无穷大舍入. . |
对于非基本算术类型的所有上述类型,使用默认模板定义 :
C ++ 98
templateclass numeric_limits { public: static const bool is_specialized = false; static T min() throw(); static T max() throw(); static const int digits = 0; static const int digits10 = 0; static const bool is_signed = false; static const bool is_integer = false; static const bool is_exact = false; static const int radix = 0; static T epsilon() throw(); static T round_error() throw(); static const int min_exponent = 0; static const int min_exponent10 = 0; static const int max_exponent = 0; static const int max_exponent10 = 0; static const bool has_infinity = false; static const bool has_quiet_NaN = false; static const bool has_signaling_NaN = false; static const float_denorm_style has_denorm = denorm_absent; static const bool has_denorm_loss = false; static T infinity() throw(); static T quiet_NaN() throw(); static T signaling_NaN() throw(); static T denorm_min() throw(); static const bool is_iec559 = false; static const bool is_bounded = false; static const bool is_modulo = false; static const bool traps = false; static const bool tinyness_before = false; static const float_round_style round_style = round_toward_zero;};
C ++ 11
templateclass numeric_limits { public: static constexpr bool is_specialized = false; static constexpr T min() noexcept { return T(); } static constexpr T max() noexcept { return T(); } static constexpr T lowest() noexcept { return T(); } static constexpr int digits = 0; static constexpr int digits10 = 0; static constexpr bool is_signed = false; static constexpr bool is_integer = false; static constexpr bool is_exact = false; static constexpr int radix = 0; static constexpr T epsilon() noexcept { return T(); } static constexpr T round_error() noexcept { return T(); } static constexpr int min_exponent = 0; static constexpr int min_exponent10 = 0; static constexpr int max_exponent = 0; static constexpr int max_exponent10 = 0; static constexpr bool has_infinity = false; static constexpr bool has_quiet_NaN = false; static constexpr bool has_signaling_NaN = false; static constexpr float_denorm_style has_denorm = denorm_absent; static constexpr bool has_denorm_loss = false; static constexpr T infinity() noexcept { return T(); } static constexpr T quiet_NaN() noexcept { return T(); } static constexpr T signaling_NaN() noexcept { return T(); } static constexpr T denorm_min() noexcept { return T(); } static constexpr bool is_iec559 = false; static constexpr bool is_bounded = false; static constexpr bool is_modulo = false; static constexpr bool traps = false; static constexpr bool tinyness_before = false;};