Integer
JavaBigInteger
や OpenSSLによく似た任意精度のクラスがありBIGNUM
ます。の無制限の制限を表現する方法を理解するのに苦労していnumeric_limit<Integer>::max()
ます。
スタック オーバーフローには、実行してもよいかどうかを尋ねる質問がいくつかあります (ユーザー定義の数値のようなクラスに std::numeric_limits を特化するのは大丈夫ですか? など) 。任意精度の整数クラスを使用した例。std::numeric_limitsリファレンス ページにもアクセスしましたが、この状況で何をすべきかが明確ではありません。
この時点で、私の結論は、 my に特化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;
};