What does numeric_limits<>::digits10 represent? 
July 23rd, 2005, 01:49 AM
| | | |
I don't get it.
In Codewarrior for Mac OS 9.4, numeric_limits<unsigned char>::digits10 == 2.
Unless I don't understand it properly (most likely!) I thought digits10 was
supposed to represent the number of digits (in base 10) a value of this type
needs. In that case, shouldn't digits10 be 3 for an unsigned char (i.e. 255
can be represented using 3 base 10 digits?), 5 for a 16-bit unsigned short,
10 for 32-bit unsigned int, etc.??
Whereas, in Codewarrior they are 2, 4 and 9 respectively.
The C++ spec (14882), section 18.2.1.2 para 9 states that its 'Number of
base 10 digits that can be represented without change'
I don't think I understand the whole sentence then, but mostly the '...
without change' bit.
Would somebody be kind enough to elaborate please.
Thanks very much.
--
Regards,
Steve. | 
July 23rd, 2005, 01:49 AM
| | | | re: What does numeric_limits<>::digits10 represent?
"Steve" <root@127.0.0.1> wrote in message
news:BE343B2E.C4B1D%root@127.0.0.1...[color=blue]
> I don't get it.
>
> In Codewarrior for Mac OS 9.4, numeric_limits<unsigned char>::digits10 ==[/color]
2.[color=blue]
>
> Unless I don't understand it properly (most likely!) I thought digits10[/color]
was[color=blue]
> supposed to represent the number of digits (in base 10) a value of this[/color]
type[color=blue]
> needs. In that case, shouldn't digits10 be 3 for an unsigned char (i.e.[/color]
255[color=blue]
> can be represented using 3 base 10 digits?), 5 for a 16-bit unsigned[/color]
short,[color=blue]
> 10 for 32-bit unsigned int, etc.??
>[/color]
I am just guessing here, but 2 10 base digits would guarantee me 0..99,
while 3 10 base digits would guarantee me 0..999.
[color=blue]
> Whereas, in Codewarrior they are 2, 4 and 9 respectively.
>
> The C++ spec (14882), section 18.2.1.2 para 9 states that its 'Number of
> base 10 digits that can be represented without change'
>
> I don't think I understand the whole sentence then, but mostly the '...
> without change' bit.
>
> Would somebody be kind enough to elaborate please.
>
> Thanks very much.
>
> --
> Regards,
> Steve.
>[/color] | 
July 23rd, 2005, 01:49 AM
| | | | re: What does numeric_limits<>::digits10 represent?
"Steve" <root@127.0.0.1> wrote...[color=blue]
>I don't get it.
>
> In Codewarrior for Mac OS 9.4, numeric_limits<unsigned char>::digits10 ==
> 2.
>
> Unless I don't understand it properly (most likely!) I thought digits10
> was
> supposed to represent the number of digits (in base 10) a value of this
> type
> needs. In that case, shouldn't digits10 be 3 for an unsigned char (i.e.
> 255
> can be represented using 3 base 10 digits?), 5 for a 16-bit unsigned
> short,
> 10 for 32-bit unsigned int, etc.??
>
> Whereas, in Codewarrior they are 2, 4 and 9 respectively.
>
> The C++ spec (14882), section 18.2.1.2 para 9 states that its 'Number of
> base 10 digits that can be represented without change'
>
> I don't think I understand the whole sentence then, but mostly the '...
> without change' bit.[/color]
If std::numeric_limits<unsigned char>::digits10 were 3, it would claim that
all numbers from 0 to 999 could be represented. That's not true. unsigned
char on your system cannot represent values above 255 without slashing the
high-order bits (or, IOW, changing the value).
V |  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 225,662 network members.
|