pete wrote:
>
> Peter Nilsson wrote:
> >
> > pete wrote:
> > > Eric Sosman wrote:
> > >
> > > > char buff[(CHAR_BIT * sizeof(n) * 10 + 32) / 33 + 1];
> > >
> > > char itoa_buff[(size_t)((sizeof(int) * CHAR_BIT  1) / 3.3) + 3];
> > > char utoa_buff[(size_t)((sizeof(int) * CHAR_BIT ) / 3.3) + 2];
> >
> > I understand the +3 over +2 (for the ''), but what is the point of
> > the ' 1' in the bitwidth calculation for signed int? Note that the
> > sign bit contributes additional value as well as the sign.
>
> INT_MAX can have, at most,
> (sizeof(int) * CHAR_BIT  1)
> value bits.
>
> In decimal notation,
> INT_MIN must have the same number of digits as INT_MAX.
>
> The only way INT_MIN could have more digits than INT_MAX
> would be if INT_MIN could be an integer power of ten, but it can't.
>
> INT_MIN must either be odd, or an integral power of two.
*Magnitude* of INT_MIN must either be odd, or an integral power of two.
A case where:
(size_t)((sizeof(int) * CHAR_BIT  1) / 3.3)
== (size_t)((sizeof(int) * CHAR_BIT) / 3.3)
sizeof(int) * CHAR_BIT == 16
char itoa_buff[7] = "32767"; /* (int)((16  1) / 3.3 + 3) == 7 */
char utoa_buff[6] = "65535"; /* (int)( 16 / 3.3 + 2) == 6 */
A case where:
(size_t)((sizeof(int) * CHAR_BIT  1) / 3.3)
!= (size_t)((sizeof(int) * CHAR_BIT) / 3.3)
sizeof(int) * CHAR_BIT == 20
char itoa_buff[8] = "524287"; /* (int)((20  1) / 3.3 + 3) == 8 */
char utoa_buff[8] = "1048575"; /* (int)( 20 / 3.3 + 2) == 8 */

pete
