Movatterモバイル変換


[0]ホーム

URL:



This page is a snapshot from the LWG issues list, see theLibrary Active Issues List for more information and the meaning ofCD1 status.

184. numeric_limits<bool> wording problems

Section: 17.3.5.3[numeric.special]Status:CD1Submitter: Gabriel Dos ReisOpened: 1999-07-21Last modified: 2016-01-28

Priority:Not Prioritized

View all otherissues in [numeric.special].

View all issues withCD1 status.

Discussion:

bools are defined by the standard to be of integer types, as per6.9.2[basic.fundamental] paragraph 7. However "integer types"seems to have a special meaning for the author of 18.2. The net effectis an unclear and confusing specification fornumeric_limits<bool> as evidenced below.

18.2.1.2/7 says numeric_limits<>::digits is, for built-in integertypes, the number of non-sign bits in the representation.

4.5/4 states that a bool promotes to int ; whereas 4.12/1 says any non zeroarithmetical value converts to true.

I don't think it makes sense at all to requirenumeric_limits<bool>::digits and numeric_limits<bool>::digits10 tobe meaningful.

The standard defines what constitutes a signed (resp. unsigned) integertypes. It doesn't categorize bool as being signed or unsigned. And the set ofvalues of bool type has only two elements.

I don't think it makes sense to require numeric_limits<bool>::is_signedto be meaningful.

18.2.1.2/18 for numeric_limits<integer_type>::radix  says:

For integer types, specifies the base of the representation.186)

This disposition is at best misleading and confusing for the standardrequires a "pure binary numeration system" for integer types as per3.9.1/7

The footnote 186) says: "Distinguishes types with base other than 2 (e.gBCD)."  This also erroneous as the standard never defines any integertypes with base representation other than 2.

Furthermore, numeric_limits<bool>::is_modulo andnumeric_limits<bool>::is_signed have similar problems.

Proposed resolution:

Append to the end of 17.3.5.3[numeric.special]:

The specialization for bool shall be provided as follows:

    namespace std {       template<> class numeric_limits<bool> {       public:         static const bool is_specialized = true;         static bool min() throw() { return false; }         static bool max() throw() { return true; }         static const int  digits = 1;         static const int  digits10 = 0;         static const bool is_signed = false;         static const bool is_integer = true;         static const bool is_exact = true;         static const int  radix = 2;         static bool epsilon() throw() { return 0; }         static bool 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 bool infinity() throw() { return 0; }         static bool quiet_NaN() throw() { return 0; }         static bool signaling_NaN() throw() { return 0; }         static bool denorm_min() throw() { return 0; }         static const bool is_iec559 = false;         static const bool is_bounded = true;         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;       };     }

[Tokyo:  The LWG desires wording that specifies exact valuesrather than more general wording in the original proposedresolution.]

[Post-Tokyo:  At the request of the LWG in Tokyo, NicoJosuttis provided the above wording.]


[8]ページ先頭

©2009-2026 Movatter.jp