Public Comment Number PC-UK0279
ISO/IEC CD2 9899 (SC22N2794) Public Comment
===========================================
Date: 1998-12-12
Author: C.D.W.Feather
Author Affiliation: Self
Postal Address:
Demon Internet Ltd.
322 Regents Park Road
London
N3 2QQ
United Kingdom
E-mail Address:
Telephone Number: +44 181 371 1138
Fax Number: +44 181 371 1037
Category: Clarification
Committee Draft subsection: 6.2.6.2
Title: Remove or clarify one's complement and sign-and-magnitude
Detailed description:
Subclause 6.2.6.2p2 makes it clear that there are only three permitted
representations for signed integers - two's complement, one's complement,
and sign-and-magnitude. It is reported, however, that certain historical
hardware using the latter two have problems with the "minus zero"
representation. Software not written with minus zero in mind can also run
into problems; for example, the expressions:
0 & 1
or
(-2 + 2) & 1
might turn out to be true because a minus zero has happened (bit operators
are defined to act on the bit patterns, so this is an issue). It is
inconvenient to have to code defensively around this problem, and most
programmers are probably not even aware of it.
However, enquiries have failed to identify any existing platform that does
not use two's complement, and so the time may have come to require it as
part of C. This approach is addressed in option A below. If WG14 is not
willing to do this, the changes in option B deal with the issues of minus
zero, by forbidding it from appearing unexpectedly.
Option A
--------
Change the last part of 6.2.6.2p2 from:
If the sign bit is zero, it shall not affect the resulting value. If
the sign bit is one, then the value shall be modified in one of the
following ways:
-- the corresponding value with sign bit 0 is negated;
-- the sign bit has the value -2N;
-- the sign bit has the value 1-2N.
to:
The sign bit shall have the value -2N.[*]
and add the footnote:
[*] This is often known as 2's complement.
Consequential changes will be required in 5.2.4.2.1, 7.18.2, and 6.7.7,
and possibly elsewhere.
Option B
--------
Change the last part of 6.2.6.2p2 from:
If the sign bit is one, then the value shall be modified in one of the
following ways:
-- the corresponding value with sign bit 0 is negated;
-- the sign bit has the value -2N;
-- the sign bit has the value 1-2N.
to:
If the sign bit is one, then the value shall be modified in one of the
following ways:
-- the corresponding value with sign bit 0 is negated (/sign and
magnitude/);
-- the sign bit has the value -2N (/two's complement/);
-- the sign bit has the value 1-2N (/one's complement/).
The implementation shall document which shall apply, and whether the
value with sign bit 1 and all value bits 0 (for the first two), or
with sign bit and all value bits 1 (for one's complement) is a trap
representation or a normal value. In the case of sign and magnitude
and one's complement, if this representation is a normal value it is
called a /negative zero/.
and insert two new paragraphs immediately afterwards:
If the implementation supports negative zeros, then they shall only be
generated by:
- the & | ^ ~ << and >> operators with appropriate arguments;
- the + - * / and % operators where one argument is a negative zero
and the result is zero;
- compound assignment operators based on the above cases.
It is unspecified if these cases actually generate negative zero or
normal zero, and whether a negative zero becomes a normal zero or
remains a negative zero when stored in an object.
If the implementation does not support negative zeros, the behavior
of an & | ^ ~ << or >> operator with appropriate arguments is undefined.