Topic: Does std::numeric_limits<integer>::digits imply binary representation?


Author: allan_w@my-dejanews.com (Allan W)
Date: Wed, 26 Mar 2003 22:43:05 +0000 (UTC)
Raw View
rmaddox@isicns.com (Randy Maddox) wrote
> bop2@telia.com ("Bo Persson") wrote
> > "Randy Maddox" <rmaddox@isicns.com> wrote
> > > I wonder if this is not a typo in 18.2.1.2?
> >
> > No, it is not. The built in types must be binary, according to 3.9.1/7:

Just because built-in types must be in binary, doesn't mean that
numeric_limits<>::digits cannot be in decimal digits.

> Even reaching way back and recalling that bit means "binary digit" the
> contrast between "digit" and "bit" in lines 6, 7 and 8 makes this, for
> me, a bit of a difficult read.  :-)

If it said "digits," I think that ordinary English usage would cause it
to mean decimal digits, not binary digits. And I think you're right...
this is exactly what was probably intended.

Anyone that was there, care to weigh in?

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: rmaddox@isicns.com (Randy Maddox)
Date: Fri, 21 Mar 2003 12:56:34 CST
Raw View
musiphil@bawi.org (KIM Seungbeom) wrote in message news:<bd47bb0e.0303201751.5242fda4@posting.google.com>...
> The existence and the definition of std::numeric_limits<>::radix,
> together with the footnote 186, seem to imply that the internal
> representation of built-in integers may be other than binary.
>
> However, std::numeric_limits<>::digits is defined as "the number
> of non-sign *bits* in the representation" [emphasis mine] for
> built-in integer types. Does this imply that the representation
> of built-in integers should be binary? If not, what would be
> the exact meaning of std::numeric_limits<>::digits?
>

I wonder if this is not a typo in 18.2.1.2?  The full text you quote
in part above is confusing when read in whole:

6 The number of radix *digits* that can be represented without change.

7 For built-in integer types, the number of non-sign *bits* in the
representation.

8 For floating point types, the number of radix *digits* in the
mantissa.

So which is it, digits or bits?  And what is the relation between
lines 6 and 7?  The name digits would certainly seem to indicate
digits rather than bits, and having different meanings depending on
the type could certainly confuse template code.

I'm sure I also fail to understand this one.  Perhaps others may
clarify?

TIA

Randy.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: bop2@telia.com ("Bo Persson")
Date: Fri, 21 Mar 2003 21:54:56 +0000 (UTC)
Raw View
"Randy Maddox" <rmaddox@isicns.com> skrev i meddelandet
news:8c8b368d.0303210638.31f796b5@posting.google.com...
> musiphil@bawi.org (KIM Seungbeom) wrote in message
news:<bd47bb0e.0303201751.5242fda4@posting.google.com>...
> > The existence and the definition of std::numeric_limits<>::radix,
> > together with the footnote 186, seem to imply that the internal
> > representation of built-in integers may be other than binary.
> >
> > However, std::numeric_limits<>::digits is defined as "the number
> > of non-sign *bits* in the representation" [emphasis mine] for
> > built-in integer types. Does this imply that the representation
> > of built-in integers should be binary? If not, what would be
> > the exact meaning of std::numeric_limits<>::digits?
> >
>
> I wonder if this is not a typo in 18.2.1.2?

No, it is not. The built in types must be binary, according to 3.9.1/7:

"... The representations of integral types shall define values by use of a
pure binary numeration system.44) [Example: this International Standard
permits 2's complement, 1's complement and signed magnitude representations
for integral types. ]"


I believe a std::numeric_limits<UDT> specialization *is* allowed to define
it differently.


Bo Persson
bop2@telia.com

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: rmaddox@isicns.com (Randy Maddox)
Date: Mon, 24 Mar 2003 15:55:53 +0000 (UTC)
Raw View
bop2@telia.com ("Bo Persson") wrote in message news:<MLLea.1457$Du.6189@newsc.telia.net>...
> "Randy Maddox" <rmaddox@isicns.com> skrev i meddelandet
> news:8c8b368d.0303210638.31f796b5@posting.google.com...
> > musiphil@bawi.org (KIM Seungbeom) wrote in message
>  news:<bd47bb0e.0303201751.5242fda4@posting.google.com>...
> > > The existence and the definition of std::numeric_limits<>::radix,
> > > together with the footnote 186, seem to imply that the internal
> > > representation of built-in integers may be other than binary.
> > >
> > > However, std::numeric_limits<>::digits is defined as "the number
> > > of non-sign *bits* in the representation" [emphasis mine] for
> > > built-in integer types. Does this imply that the representation
> > > of built-in integers should be binary? If not, what would be
> > > the exact meaning of std::numeric_limits<>::digits?
> > >
> >
> > I wonder if this is not a typo in 18.2.1.2?
>
> No, it is not. The built in types must be binary, according to 3.9.1/7:
>
> "... The representations of integral types shall define values by use of a
> pure binary numeration system.44) [Example: this International Standard
> permits 2's complement, 1's complement and signed magnitude representations
> for integral types. ]"
>
>
> I believe a std::numeric_limits<UDT> specialization *is* allowed to define
> it differently.
>
>
> Bo Persson
> bop2@telia.com
>

Thanks for the response.  I was already aware of this, and yet I still
find the following text from 18.2.1.2 somewhat less than clear due to
the use of "digits" in the name versus "digits" and "bits" in the
text:

> 6 The number of radix *digits* that can be represented without change.

> 7 For built-in integer types, the number of non-sign *bits* in the
> representation.

> 8 For floating point types, the number of radix *digits* in the
> mantissa.

Even reaching way back and recalling that bit means "binary digit" the
contrast between "digit" and "bit" in lines 6, 7 and 8 makes this, for
me, a bit of a difficult read.  :-)

Randy.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: musiphil@bawi.org (KIM Seungbeom)
Date: Fri, 21 Mar 2003 05:05:50 +0000 (UTC)
Raw View
The existence and the definition of std::numeric_limits<>::radix,
together with the footnote 186, seem to imply that the internal
representation of built-in integers may be other than binary.

However, std::numeric_limits<>::digits is defined as "the number
of non-sign *bits* in the representation" [emphasis mine] for
built-in integer types. Does this imply that the representation
of built-in integers should be binary? If not, what would be
the exact meaning of std::numeric_limits<>::digits?

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]