Unlities之numeric_limits
来源:互联网 发布:工商银行网络银行 编辑:程序博客网 时间:2024/04/30 21:45
用numeric_limits可以为每一个类型提供一个接口。
A general template provides the default numeric values for any type:
namespace std {
/* general numeric limits as default for any type
*/
template <class T>
class numeric_limits
{
public:
static const bool is_specialized = false;//no specialization for numeric limits exist
... //other members that are meaningless for the generalnumeric limits
};
}
? Specializations of the template define the numeric limits for each numeric type as follows:
namespace std {
template<> class numeric_limits<int>
{
public:
static const bool is_specialized = true;//yes, a specialization for numeric limits of int does exist
static T min() throw() { return -2147483648;}
static T max() throw() { return 2147483647;}
static const int digits = 31;
...
};
}
float的完全特化:
namespace std {
class numeric_limits<float> {
public:
//yes, a specialization for numeric limits of float does exist
static const bool is_specialized = true;
inline static float min() throw() {
return 1.17549435E-38F;
}
inline static float max() throw() {
return 3.40282347E+38F;
}
static const int digits = 24;
static const int digits10 = 6;
static const bool is_signed = true;
static const bool is_integer = false;
static const bool is_exact = false;
static const bool is_bounded = true;
static const bool is_modulo = false;
static const bool is_iec559 = true;
static const int radix = 2;
inline static float epsilon() throw() {
return 1.19209290E-07F;
}
static const float_round_style round_style
= round_to_nearest;
inline static float round_error() throw() {
return 0.5F;
}
static const int min_exponent = -125;
static const int max_exponent = +128;
static const int min_exponentl0 = -37;
static const int max_exponent10 = 38;
static const bool has_infinity = true;
inline static float infinity() throw() { return ...; }
static const bool has_quiet_NaN = true;
inline static float quiet_NaN() throw() { return ...; }
static const bool has_signaling_NaN = true;
inline static float signaling_NaN() throw() { return ...; }
static const float_denorm_style has_denorm = denorm_absent;
static const bool has_denorm_loss = false;
inline static float denorm_rain() throw() { return min(); }
static const bool traps = true;
static const bool tinyness_before = true;
};
}
这上面的代码中应该可以知道numeric_limits是干什么的了。
A general template provides the default numeric values for any type:
namespace std {
/* general numeric limits as default for any type
*/
template <class T>
class numeric_limits
{
public:
static const bool is_specialized = false;//no specialization for numeric limits exist
... //other members that are meaningless for the generalnumeric limits
};
}
? Specializations of the template define the numeric limits for each numeric type as follows:
namespace std {
template<> class numeric_limits<int>
{
public:
static const bool is_specialized = true;//yes, a specialization for numeric limits of int does exist
static T min() throw() { return -2147483648;}
static T max() throw() { return 2147483647;}
static const int digits = 31;
...
};
}
float的完全特化:
namespace std {
class numeric_limits<float> {
public:
//yes, a specialization for numeric limits of float does exist
static const bool is_specialized = true;
inline static float min() throw() {
return 1.17549435E-38F;
}
inline static float max() throw() {
return 3.40282347E+38F;
}
static const int digits = 24;
static const int digits10 = 6;
static const bool is_signed = true;
static const bool is_integer = false;
static const bool is_exact = false;
static const bool is_bounded = true;
static const bool is_modulo = false;
static const bool is_iec559 = true;
static const int radix = 2;
inline static float epsilon() throw() {
return 1.19209290E-07F;
}
static const float_round_style round_style
= round_to_nearest;
inline static float round_error() throw() {
return 0.5F;
}
static const int min_exponent = -125;
static const int max_exponent = +128;
static const int min_exponentl0 = -37;
static const int max_exponent10 = 38;
static const bool has_infinity = true;
inline static float infinity() throw() { return ...; }
static const bool has_quiet_NaN = true;
inline static float quiet_NaN() throw() { return ...; }
static const bool has_signaling_NaN = true;
inline static float signaling_NaN() throw() { return ...; }
static const float_denorm_style has_denorm = denorm_absent;
static const bool has_denorm_loss = false;
inline static float denorm_rain() throw() { return min(); }
static const bool traps = true;
static const bool tinyness_before = true;
};
}
这上面的代码中应该可以知道numeric_limits是干什么的了。
0 0
- Unlities之numeric_limits
- numeric_limits
- numeric_limits
- numeric_limits
- numeric_limits
- numeric_limits
- numeric_limits
- 关于numeric_limits
- 关于numeric_limits
- 关于numeric_limits
- numeric_limits用法
- numeric_limits 解析
- 数值极限numeric_limits
- numeric_limits的运用
- 数值极限numeric_limits
- 数值极限numeric_limits
- C++ STL : numeric_limits
- std::numeric_limits::max() std::numeric_limits::min()编译错误
- Utilities之auto_ptr
- 【转】DataGridView 的重绘
- DOM解析XML(二)
- try catch多个catch捕获问题
- hdu2065--红色病毒
- Unlities之numeric_limits
- c++ double类型的误差
- [iOS Crash文件分析]-如何使用symbolicatecrash工具
- 烤鸭的gerrit使用总结
- 单元测试之覆盖率浅谈
- 怎么查询局域网内全部电脑IP和mac地址等信息?
- 人脸识别之LBPH
- CCS3.1调试总结
- 动态规划学习系列——数位DP(练手一)