On 12 Aug 2005 06:06:12 -0700, "REH" <(E-Mail Removed)> wrote in

comp.lang.c++:

> If the is_modulo field of the numeric_limits class is true for signed

> integer types, can I assume that overflow for such types is defined

> behavior? If so, is the behavior the same regardless of

> implementation?
I'd suggest asking this one in comp.std.c for a definitive answer, but

I would say no. That is, if is_modulo can be true for a signed

integer type. I can't find anything in the standard that says either

way.

Not undefined in the sense that it will explode, but in the sense that

there is no definitive answer.

If you perform arithmetic on unsigned types that over- or underflows,

the result is well-defined and exact. If you perform arithmetic on

signed integer types that does not over- or underflow, the result is

well-defined.

But let's take a platform with 16 bit ints (to keep the numbers

small), and let's assume that the bits of the result are the same as

if the values were unsigned types.

If you add 0x7FFF and 0x0001, values of 32767 and 1, and the adder

produces 0x8000, what is the value? On a signed-magnitude

representation, this is -0. On a 1's complement platform, it is

-32767. And on a 2's complement platform it would be -32768.

Since there is no unique answer, and it is not specifically stated in

the standard that it is implementation-defined or unspecified, that

pretty much makes it undefined in that sense.

> Also, if the range of an integer type is not symmetrical around zero

> (i.e., 2's comp.), is it safe to assume that the extra value(s) is one

> the negative side?
Unfortunately the C++ standard is not as specific about the details of

how negative integer values are represented as is the 1999 C standard.

But given that the C++ standard specifically states, as the C standard

does, that it allows exactly three types of representation, and 2's

complement is the only one of the three that can be unsymmetrical, the

fact is that there is one and only one "unmatched" value, and it is

indeed on the negative side.

--

Jack Klein

Home:

http://JK-Technology.Com
FAQs for

comp.lang.c

http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++

http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++

http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html