jww*_*jww 8 c++ numeric-limits c++03
我有一个任意的精度Integer类,它很像Java BigInteger或OpenSSL BIGNUM在运行.我无法理解我应该如何表达无限制的限制numeric_limit<Integer>::max().
Stack Overflow有几个问题,询问它是否可以执行(比如可以将std :: numeric_limits专门用于用户定义的类似数字的类吗?),以及一些使用基元的示例的答案,但我没有看到使用任意精度整数类的示例.我还访问了std :: numeric_limits参考页面,但我不清楚在这种情况下我应该做些什么.
在这一点上,我的内容是可以专注numeric_limit于我的Integer,并且可以将它放在标准命名空间中.我还需要专注于所有人numeric_limits.
如何指定无限制的限制numeric_limit<T>::max()?
以下是GCC 4.2.1 <limits>(OS X机器).
/// numeric_limits<int> specialization.
template<>
struct numeric_limits<int>
{
static const bool is_specialized = true;
static int min() throw()
{ return -__INT_MAX__ - 1; }
static int max() throw()
{ return __INT_MAX__; }
static const int digits = __glibcxx_digits (int);
static const int digits10 = __glibcxx_digits10 (int);
static const bool is_signed = true;
static const bool is_integer = true;
static const bool is_exact = true;
static const int radix = 2;
static int epsilon() throw()
{ return 0; }
static int round_error() throw()
{ return 0; }
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 int infinity() throw()
{ return static_cast<int>(0); }
static int quiet_NaN() throw()
{ return static_cast<int>(0); }
static int signaling_NaN() throw()
{ return static_cast<int>(0); }
static int denorm_min() throw()
{ return static_cast<int>(0); }
static const bool is_iec559 = false;
static const bool is_bounded = true;
static const bool is_modulo = true;
static const bool traps = __glibcxx_integral_traps;
static const bool tinyness_before = false;
static const float_round_style round_style = round_toward_zero;
};
Run Code Online (Sandbox Code Playgroud)
该标准对max§18.3.2.4中的成员函数进行了以下说明:
对于所有专业都有意义
is_bounded != false.
因此,您应该在课程的文档中指定并指定它是没有意义的.is_bounded falsestd::numeric_limits<T>::max
| 归档时间: |
|
| 查看次数: |
161 次 |
| 最近记录: |