Topic: Integer representation (Was: Maximum size that an array can hold in C++)


Author: Bart van Ingen Schenau <bart@ingen.ddns.info>
Date: Thu, 11 Jun 2009 10:27:08 CST
Raw View
[cross-posted to comp.lang.c++ and comp.std.c++]
Alf P. Steinbach wrote:

> * Bart van Ingen Schenau:
>> Alf P. Steinbach wrote:
>>
>>> * Bart van Ingen Schenau:
>>>> Pascal J. Bourguignon wrote:
>>>>
>>>>> Bart van Ingen Schenau <bart@ingen.ddns.info> writes:
>>>>>
>>>>>> The standard states so in 4.7/2: "If the destination type is
>>>>>> unsigned, the resulting valu is the least unsigned integer
>>>>>> congruent to the source integer (modulo 2^n where n is the number
>>>>>> of bits used to represent the unsigned type)."
>>>>> If the machine represents unsigned integers as 10-digits BCD
>>>>> numbers, then the number of bits used to represent the unsigned is
>>>>> 10*log(10)/log(2) = 33.2192809488...
>>>>>
>>>>> If we take n=34, 2^34 > 10^10 so it's not possible.  If we take
>>>>> n=33, 2^33 < 10^10 so 2^n is not the greatest unsigned integer
>>>>> (10^10-1).
>>>>>
>>>>> Oops!
>>>> As I quoted the C++ standard literally, this only shows that there
>>>> is an unwritten assumption in the standard. This unwritten
>>>> assumption is that a pure binary value-representation is used for
>>>> (at least) unsigned integer types.
>>> That requirement is explicitly stated in the standard.
>>
>> Could you give a reference?
>
> James just did else-thread. :-)
>
No he didn't. He stated what we "know" to be true: that a binary
representation is needed for the integer types. But he did not provide
C&V for the clause that actually says so.

I am not contesting the knowledge that integers must have a pure binary
representation, but I am troubled by the fact that I am unable to locate
this requirement in the standard.

Perhaps the folks in comp.std.c++ can help us in locating the clause
that I keep missing.

>
> Cheers & hth.,
>
> - Alf
>

Bart v Ingen Schenau
--
a.c.l.l.c-c++ FAQ: http://www.comeaucomputing.com/learn/faq
c.l.c FAQ: http://c-faq.com/
c.l.c++ FAQ: http://www.parashift.com/c++-faq-lite/


[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: "Alf P. Steinbach" <alfps@start.no>
Date: Thu, 11 Jun 2009 14:06:21 CST
Raw View
* Bart van Ingen Schenau:
>
> [cross-posted to comp.lang.c++ and comp.std.c++]
> Alf P. Steinbach wrote:
>
>> * Bart van Ingen Schenau:
>>>
>>> Alf P. Steinbach wrote:
>>>
>>>> * Bart van Ingen Schenau:
>>>>>
>>>>> Pascal J. Bourguignon wrote:
>>>>>
>>>>>> Bart van Ingen Schenau <bart@ingen.ddns.info> writes:
>>>>>>
>>>>>>> The standard states so in 4.7/2: "If the destination type is
>>>>>>> unsigned, the resulting valu is the least unsigned integer
>>>>>>> congruent to the source integer (modulo 2^n where n is the number
>>>>>>> of bits used to represent the unsigned type)."
>>>>>>
>>>>>> If the machine represents unsigned integers as 10-digits BCD
>>>>>> numbers, then the number of bits used to represent the unsigned is
>>>>>> 10*log(10)/log(2) = 33.2192809488...
>>>>>>
>>>>>> If we take n=34, 2^34 > 10^10 so it's not possible.  If we take
>>>>>> n=33, 2^33 < 10^10 so 2^n is not the greatest unsigned integer
>>>>>> (10^10-1).
>>>>>>
>>>>>> Oops!
>>>>>
>>>>> As I quoted the C++ standard literally, this only shows that there
>>>>> is an unwritten assumption in the standard. This unwritten
>>>>> assumption is that a pure binary value-representation is used for
>>>>> (at least) unsigned integer types.
>>>>
>>>> That requirement is explicitly stated in the standard.
>>>
>>> Could you give a reference?
>>
>> James just did else-thread. :-)
>>
> No he didn't. He stated what we "know" to be true: that a binary
> representation is needed for the integer types. But he did not provide
> C&V for the clause that actually says so.

He did.

James quoted: "the representations of integral types shall define values
by use of a pure binary numeration system."

Searching for the last 3 words of that quote, in the standard, lands
you at    3.9.1/7.

Hah, I'm much better at searching than you!

Yay! :-)


> I am not contesting the knowledge that integers must have a pure binary
> representation, but I am troubled by the fact that I am unable to locate
> this requirement in the standard.
>
> Perhaps the folks in comp.std.c++ can help [me] in locating the clause
> that I keep missing.

Posting there you'd just have me answering your question again.

It would be rather silly to trust me more, or less, depending on the
forum, or depending on which hat I'm wearing at the moment.


Cheers & hth.,

- Alf

--
Due to hosting requirements I need visits to <url: http://alfps.izfree.com/>.
No ads, and there is some C++ stuff! :-) Just going there is good. Linking
to it is even better! Thanks in advance!


[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: "Bo Persson" <bop@gmb.dk>
Date: Thu, 11 Jun 2009 16:40:55 CST
Raw View
Bart van Ingen Schenau wrote:
> [cross-posted to comp.lang.c++ and comp.std.c++]
> Alf P. Steinbach wrote:
>
>> * Bart van Ingen Schenau:
>>> Alf P. Steinbach wrote:
>>>
>>>> * Bart van Ingen Schenau:
>>>>> Pascal J. Bourguignon wrote:
>>>>>
>>>>>> Bart van Ingen Schenau <bart@ingen.ddns.info> writes:
>>>>>>
>>>>>>> The standard states so in 4.7/2: "If the destination type is
>>>>>>> unsigned, the resulting valu is the least unsigned integer
>>>>>>> congruent to the source integer (modulo 2^n where n is the
>>>>>>> number of bits used to represent the unsigned type)."
>>>>>> If the machine represents unsigned integers as 10-digits BCD
>>>>>> numbers, then the number of bits used to represent the
>>>>>> unsigned is 10*log(10)/log(2) = 33.2192809488...
>>>>>>
>>>>>> If we take n=34, 2^34 > 10^10 so it's not possible.  If we take
>>>>>> n=33, 2^33 < 10^10 so 2^n is not the greatest unsigned integer
>>>>>> (10^10-1).
>>>>>>
>>>>>> Oops!
>>>>> As I quoted the C++ standard literally, this only shows that
>>>>> there is an unwritten assumption in the standard. This unwritten
>>>>> assumption is that a pure binary value-representation is used
>>>>> for (at least) unsigned integer types.
>>>> That requirement is explicitly stated in the standard.
>>>
>>> Could you give a reference?
>>
>> James just did else-thread. :-)
>>
> No he didn't. He stated what we "know" to be true: that a binary
> representation is needed for the integer types. But he did not
> provide C&V for the clause that actually says so.
>
> I am not contesting the knowledge that integers must have a pure
> binary representation, but I am troubled by the fact that I am
> unable to locate this requirement in the standard.
>
> Perhaps the folks in comp.std.c++ can help us in locating the clause
> that I keep missing.

I find it in [basic.fundamental], 3.9.1/7:

"Types bool, char, wchar_t, and the signed and unsigned integer types
are collectively called integral
types. A synonym for integral type is integer type. The
representations of integral types shall define values
by use of a pure binary numeration system. [Example: this
International Standard permits 2's complement,
1's complement and signed magnitude representations for integral
types. ]"

which I guess is what James was referring to.


Bo Persson




--
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: Bart van Ingen Schenau <bart@ingen.ddns.info>
Date: Fri, 12 Jun 2009 11:06:20 CST
Raw View
Alf P. Steinbach wrote:

> * Bart van Ingen Schenau:
>>
>> [cross-posted to comp.lang.c++ and comp.std.c++]
>>
>> No he didn't. He stated what we "know" to be true: that a binary
>> representation is needed for the integer types. But he did not
>> provide C&V for the clause that actually says so.
>
> He did.
>
> James quoted: "the representations of integral types shall define
> values by use of a pure binary numeration system."
>
> Searching for the last 3 words of that quote, in the standard, lands
> you at    3.9.1/7.

Thanks. For some reason, my mind kept skipping over that sentence every
time I looked at my (dead tree) copy of the standard.

>
> Hah, I'm much better at searching than you!

I am not going to comment on that ;-)

>
> Yay! :-)
>
>
>> I am not contesting the knowledge that integers must have a pure
>> binary representation, but I am troubled by the fact that I am unable
>> to locate this requirement in the standard.
>>
>> Perhaps the folks in comp.std.c++ can help [me] in locating the
>> clause that I keep missing.
>
> Posting there you'd just have me answering your question again.
>
> It would be rather silly to trust me more, or less, depending on the
> forum, or depending on which hat I'm wearing at the moment.

As I did not send a separate message to c.s.c++, but rather cross-posted
my previous message, you already answered in both groups.
And it is not that my trust level depends on the group, but rather to
give more people a chance to show they are better at searching than I
am. :-)

>
>
> Cheers & hth.,
>
> - Alf
>
Bart v Ingen Schenau
--
a.c.l.l.c-c++ FAQ: http://www.comeaucomputing.com/learn/faq
c.l.c FAQ: http://c-faq.com/
c.l.c++ FAQ: http://www.parashift.com/c++-faq-lite/


[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]