Namespaces
Variants
Views
Actions

Talk:cpp/language/types

From cppreference.com

[edit] numeric limits

Quote:

It's tempting to write -128 here, but the Standard-guaranteed numeric_limits<signed char>::min() (and SCHAR_MIN) is -127, even if every implementation uses -128 (the reason is that the Standard supports 2's complement, 1's complement, and Sign-and-magnitude representations of negatives). Same for all other mins.
Reference: 18.3.2.4[numeric.limits.members] which refers to 18.3.3[c.limits]/2 which refers to ISO 9899:1999 5.2.4.2.1.

Even if the Standard defines generalized limits, it still would be a good idea to stick to the data models and report what actual limits the implementations have, not what the Standard defines. For example, the Standard defines neither the format nor the limits for the floating point types, but what the actual implementations provide is still a relevant fact. That's not to say that the odd lower limit for the signed integers should not be mentioned. P12 07:48, 24 September 2011 (PDT)

True.. and considering there's probably no C++ compilers for one's compl and sign-and-magnitude machines, maybe it should even give the usual 2's comp in the table and mention the standard guarantees in a note. --Cubbi 08:40, 24 September 2011 (PDT)

[edit] size hierarchy

This edit seems to have gotten lost, I think it's a pretty important guarantee -- otherwise, as the page is written now, with "at least" limits only, int could be bigger than long. --Cubbi 08:47, 24 September 2011 (PDT)

[edit] C++ standard bit numbers

Does the C++ standard really guarantee certain bit number minimums as the table shows? If not, where did those numbers come from? I've seen them on Wikipedia too but I haven't found a reference in the standard. Pubby 01:51, 15 May 2012 (PDT)

It guarantees that the types are able to represent every value from a given range ([-127, +127] for signed char, for example). It doesn't directly say that char is at least 8 bits, but you can't represent that many distinct values with less than 8. --Cubbi 05:48, 15 May 2012 (PDT)
Do you happen to have a reference for where the standard makes claims about required ranges? The closest I've been able to find so far is 3.9.1 (which might be interpreted to say something about the storage requirements for int) but I haven't found anything else. --Nate 07:06, 15 May 2012 (PDT)
18.3.2.4[numeric.limits.members] which refers to 18.3.3[c.limits]/2 which refers to ISO 9899:1999 5.2.4.2.1 (oh, actually char is the one type where the number of bits is specified explicitly: no less than 8) --Cubbi 07:52, 15 May 2012 (PDT)
Got it. Thanks Cubbi.  :) --Nate 13:58, 15 May 2012 (PDT)