I have an arbitrary precision Integer
class, which is a lot like Java's BigInteger
or OpenSSL's BIGNUM
in operation. I'm having trouble understanding how I should express an unbounded limit for numeric_limit<Integer>::max()
.
Stack Overflow has a couple of question that asks if its OK to do (like Is it ok to specialize std::numeric_limits for user-defined number-like classes?), and some answers with some examples using primitives, but I did not see an example using an arbitrary precision integer class. I also visited std::numeric_limits reference page but its not clear to me what I should do in this situation.
At this point, my takeaway is its OK to specialize numeric_limit
for my Integer
, and its OK to put it in the standard namespace. I also need to specialize all numeric_limits
.
How do I specify an unbounded limit for numeric_limit<T>::max()
?
Below is from GCC 4.2.1's <limits>
(OS X machine).
/// 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;
};
The standard says the following about the
max
member function in ยง18.3.2.4:So you should make
is_bounded
false
and specify in the documentation for your class that it does not make sense to callstd::numeric_limits<T>::max
on it.