Skip to content

Commit 5d81baf

Browse files
authored
Merge 2018-11 CWG Motion 10
P1236R1 Alternative Wording for P0907R4 Signed Integers are Two's Complement Fixes #2402
2 parents 8470169 + 3b7ee00 commit 5d81baf

File tree

6 files changed

+259
-205
lines changed

6 files changed

+259
-205
lines changed

source/atomics.tex

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,8 +1029,13 @@
10291029
\pnum
10301030
\indextext{signed integer representation!two's complement}%
10311031
\remarks For signed integer types,
1032-
arithmetic is defined to use two's complement representation.
1033-
There are no undefined results.
1032+
the result is as if the object value and parameters
1033+
were converted to their corresponding unsigned types,
1034+
the computation performed on those types, and
1035+
the result converted back to the signed type.
1036+
\begin{note}
1037+
There are no undefined results arising from the computation.
1038+
\end{note}
10341039
\end{itemdescr}
10351040

10361041
\indexlibrarymember{operator+=}{atomic_ref<\placeholder{integral}>}%
@@ -1894,8 +1899,15 @@
18941899

18951900
\pnum
18961901
\indextext{signed integer representation!two's complement}%
1897-
\remarks For signed integer types, arithmetic is defined to use two's complement representation.
1898-
There are no undefined results.
1902+
\remarks For signed integer types,
1903+
the result is as if the object value and parameters
1904+
were converted to their corresponding unsigned types,
1905+
the computation performed on those types, and
1906+
the result converted back to the signed type.
1907+
\begin{note}
1908+
There are no undefined results arising from the computation.
1909+
\end{note}
1910+
18991911
\end{itemdescr}
19001912

19011913
\indexlibrarymember{operator+=}{atomic<T*>}%

source/basic.tex

Lines changed: 149 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -4165,51 +4165,7 @@
41654165
\rSec2[basic.fundamental]{Fundamental types}
41664166

41674167
\pnum
4168-
\indextext{type!integral}%
4169-
\indextext{floating-point type|see{type, floating-point}}%
41704168
\indextext{type!implementation-defined \tcode{sizeof}}%
4171-
\indextext{type!Boolean}%
4172-
\indextext{type!\idxcode{char}}%
4173-
\indextext{type!character}%
4174-
Objects declared as characters (\tcode{char}) shall be large enough to
4175-
store any member of the implementation's basic character set. If a
4176-
character from this set is stored in a character object, the integral
4177-
value of that character object is equal to the value of the single
4178-
character literal form of that character. It is \impldef{signedness of \tcode{char}}
4179-
whether a \tcode{char} object can hold negative values.
4180-
\indextext{\idxcode{char}!implementation-defined sign of}%
4181-
\indextext{type!\idxcode{signed char}}%
4182-
\indextext{type!\idxcode{unsigned char}}%
4183-
Characters can be explicitly declared \tcode{unsigned} or
4184-
\tcode{signed}.
4185-
\indextext{character!\idxcode{signed}}%
4186-
Plain \tcode{char}, \tcode{signed char}, and \tcode{unsigned char} are
4187-
three distinct types, collectively called
4188-
\defnx{narrow character types}{type!narrow character}.
4189-
A \tcode{char}, a \tcode{signed char}, and an
4190-
\tcode{unsigned char} occupy the same amount of storage and have the
4191-
same alignment requirements\iref{basic.align}; that is, they have the
4192-
same object representation. For narrow character types, all bits of the object
4193-
representation participate in the value representation.
4194-
\begin{note}
4195-
A bit-field of narrow character type whose length is larger than
4196-
the number of bits in the object representation of that type has
4197-
padding bits; see~\ref{basic.types}.
4198-
\end{note}
4199-
For unsigned narrow
4200-
character types, each possible bit pattern of the value representation
4201-
represents a distinct number. These requirements do not hold for other types. In
4202-
any particular implementation, a plain \tcode{char} object can take on
4203-
either the same values as a \tcode{signed char} or an \tcode{unsigned
4204-
char}; which one is \impldef{representation of \tcode{char}}.
4205-
For each value \placeholder{i} of type \tcode{unsigned char} in the range
4206-
0 to 255 inclusive, there exists a value \placeholder{j} of type
4207-
\tcode{char} such that the result of an integral
4208-
conversion\iref{conv.integral} from \placeholder{i} to \tcode{char} is
4209-
\placeholder{j}, and the result of an integral conversion from
4210-
\placeholder{j} to \tcode{unsigned char} is \placeholder{i}.
4211-
4212-
\pnum
42134169
\indextext{type!standard signed integer}%
42144170
There are five \defnx{standard signed integer types}{standard signed integer type} :
42154171
\indextext{type!\idxcode{signed char}}%
@@ -4225,20 +4181,21 @@
42254181
\indextext{type!signed integer}%
42264182
There may also be \impldef{extended signed integer types}
42274183
\defnx{extended signed integer types}{extended signed integer type}.
4228-
The standard and
4229-
extended signed integer types are collectively called
4184+
The standard and extended signed integer types are collectively called
42304185
\defnx{signed integer types}{signed integer type}.
4186+
The range of representable values for a signed integer type is
4187+
$-2^{N-1}$ to $2^{N-1}-1$ (inclusive),
4188+
where \placeholder{N} is called the \defn{range exponent} of the type.
42314189
\indextext{integral type!implementation-defined \tcode{sizeof}}%
42324190
\begin{note}
4233-
Plain \tcode{int}s
4234-
are intended to have
4235-
the natural size suggested by the architecture of the
4236-
execution environment;
4191+
Plain \tcode{int}s are intended to have
4192+
the natural size suggested by the architecture of the execution environment;
42374193
the other signed integer types are provided to meet special needs.
42384194
\end{note}
42394195

42404196
\pnum
42414197
\indextext{type!\idxcode{unsigned}}%
4198+
\indextext{type!unsigned integer}%
42424199
For each of the standard signed integer types,
42434200
there exists a corresponding (but different)
42444201
\indextext{type!standard unsigned integer}%
@@ -4250,98 +4207,176 @@
42504207
\indextext{type!\idxcode{unsigned long long}}%
42514208
``\tcode{unsigned char}'', ``\tcode{unsigned short int}'',
42524209
``\tcode{unsigned int}'', ``\tcode{unsigned long int}'', and
4253-
``\tcode{unsigned long long int}'', each of
4254-
which occupies the same amount of storage and has the same alignment
4255-
requirements\iref{basic.align} as the corresponding signed integer
4256-
type\footnote{See~\ref{dcl.type.simple} regarding the correspondence between types and
4257-
the sequences of \grammarterm{type-specifier}{s} that designate them.};
4258-
that is, each signed integer type has the same object representation as
4259-
its corresponding unsigned integer type.
4210+
``\tcode{unsigned long long int}''.
42604211
\indextext{type!extended unsigned integer}%
4261-
\indextext{type!unsigned integer}%
4262-
Likewise, for each of the extended signed integer types there exists a
4263-
corresponding
4264-
\defn{extended unsigned integer type} with the same amount of storage and alignment
4265-
requirements. The standard and extended unsigned integer types are
4266-
collectively called \defnx{unsigned integer types}{unsigned integer type}. The range of non-negative
4267-
values of a signed integer type is
4268-
a subrange of the corresponding unsigned integer type,
4269-
the representation of the same value in each of the two types is the same, and
4270-
the value representation of each corresponding signed/unsigned type shall be the same.
4212+
Likewise, for each of the extended signed integer types,
4213+
there exists a corresponding \defn{extended unsigned integer type}.
4214+
The standard and extended unsigned integer types
4215+
are collectively called \defnx{unsigned integer types}{unsigned integer type}.
4216+
An unsigned integer type has the same range exponent \placeholder{N}
4217+
as the corresponding signed integer type.
4218+
\indextext{arithmetic!\idxcode{unsigned}}%
4219+
The range of representable values for the unsigned type is
4220+
$0$ to $2^N-1$ (inclusive);
4221+
arithmetic for the unsigned type is performed modulo $2^N$.
4222+
\begin{note}
4223+
Unsigned arithmetic does not overflow.
4224+
Overflow for signed arithmetic yields undefined behavior\iref{expr.pre}.
4225+
\end{note}
4226+
4227+
\pnum
4228+
\indextext{signed integer representation!two's complement}%
4229+
An unsigned integer type has the same
4230+
object representation,
4231+
value representation, and
4232+
alignment requirements\iref{basic.align}
4233+
as the corresponding signed integer type.
4234+
For each value $x$ of a signed integer type,
4235+
the value of the corresponding unsigned integer type
4236+
congruent to $x$ modulo $2^N$ has the same value
4237+
of corresponding bits in its value representation.\footnote{This
4238+
is also known as two's complement representation.}
4239+
\begin{example}
4240+
The value $-1$ of a signed integer type has the same representation as
4241+
the largest value of the corresponding unsigned type.
4242+
\end{example}
4243+
4244+
\begin{floattable}{Minimum range exponent}{tab:range.exponent}{ll}
4245+
\topline
4246+
\lhdr{Type} & \rhdr{Minimum range exponent $N$} \\
4247+
\capsep
4248+
\tcode{signed char} & 8 \\
4249+
\tcode{short} & 16 \\
4250+
\tcode{int} & 16 \\
4251+
\tcode{long} & 32 \\
4252+
\tcode{long long} & 64 \\
4253+
\end{floattable}
4254+
4255+
\pnum
4256+
The range exponent of each signed integer type
4257+
shall not be less than the values specified in \tref{range.exponent}.
4258+
The value representation of a signed or unsigned integer type
4259+
comprises $N$ bits, where N is the respective range exponent.
4260+
Each set of values for any padding bits\iref{basic.types}
4261+
in the object representation are
4262+
alternative representations of the value specified by the value representation.
4263+
\begin{note}
4264+
Padding bits have unspecified value, but do not cause traps.
4265+
See also ISO C 6.2.6.2.
4266+
\end{note}
4267+
\begin{note}
4268+
The signed and unsigned integer types satisfy
4269+
the constraints given in ISO C 5.2.4.2.1.
4270+
\end{note}
4271+
Except as specified above,
4272+
the range exponent of a signed or unsigned integer type is
4273+
\impldef{range exponent of integral type}.
4274+
4275+
\pnum
4276+
Each value $x$ of an unsigned integer type with range exponent $N$ has
4277+
a unique representation $x = x_0 2^0 + x_1 2^1 + \ldots + x_{N-1} 2^{N-1}$,
4278+
where each coefficient $x_i$ is either 0 or 1;
4279+
this is called the \defn{base-2 representation} of $x$.
4280+
The base-2 representation of a value of signed integer type is
4281+
the base-2 representation of the congruent value
4282+
of the corresponding unsigned integer type.
42714283
\indextext{type!standard integer}%
42724284
\indextext{type!extended integer}%
42734285
The standard signed integer types and standard unsigned integer types
42744286
are collectively called the \defnx{standard integer types}{standard integer type}, and the extended
42754287
signed integer types and extended
42764288
unsigned integer types are collectively called the
42774289
\defnx{extended integer types}{extended integer type}.
4278-
The signed and unsigned integer types shall satisfy
4279-
the constraints given in the C standard, subclause 5.2.4.2.1.
42804290

42814291
\pnum
4282-
\indextext{arithmetic!\idxcode{unsigned}}%
4283-
Unsigned integers shall obey the laws of arithmetic modulo $2^n$ where $n$ is
4284-
the number of bits in the value representation of that particular size of
4285-
integer.\footnote{This implies that
4286-
unsigned arithmetic does not overflow because a result
4287-
that cannot be represented by the resulting unsigned integer type is
4288-
reduced modulo the number that is one greater than the largest value
4289-
that can be represented by the resulting unsigned integer type.}
4292+
A fundamental type specified to have
4293+
a signed or unsigned integer type as its \defn{underlying type} has
4294+
the same object representation,
4295+
value representation,
4296+
alignment requirements\iref{basic.align}, and
4297+
range of representable values as the underlying type.
4298+
Further, each value has the same representation in both types.
4299+
4300+
\pnum
4301+
\indextext{type!\idxcode{char}}%
4302+
\indextext{type!character}%
4303+
\indextext{type!narrow character}%
4304+
\indextext{\idxcode{char}!implementation-defined sign of}%
4305+
\indextext{type!\idxcode{signed char}}%
4306+
\indextext{character!\idxcode{signed}}%
4307+
\indextext{type!\idxcode{unsigned char}}%
4308+
Type \tcode{char} is a distinct type
4309+
that has an \impldef{underlying type of \tcode{char}} choice of
4310+
``\tcode{signed char}'' or ``\tcode{unsigned char}'' as its underlying type.
4311+
The values of type \tcode{char} can represent distinct codes
4312+
for all members of the implementation's basic character set.
4313+
The three types \tcode{char}, \tcode{signed char}, and \tcode{unsigned char}
4314+
are collectively called \defnx{narrow character types}{narrow character type}.
4315+
For narrow character types,
4316+
each possible bit pattern of the object representation represents
4317+
a distinct value.
4318+
\begin{note}
4319+
This requirement does not hold for other types.
4320+
\end{note}
4321+
\begin{note}
4322+
A bit-field of narrow character type whose width is larger than
4323+
the range exponent of that type has padding bits; see \ref{basic.types}.
4324+
\end{note}
42904325

42914326
\pnum
4327+
\indextext{\idxcode{wchar_t}|see{type, \tcode{wchar_t}}}%
4328+
\indextext{type!\idxcode{wchar_t}}%
4329+
\indextext{underlying type|see{type, underlying}}%
4330+
\indextext{type!underlying!\idxcode{wchar_t}}%
4331+
Type \tcode{wchar_t} is a distinct type that has
4332+
an \impldef{underlying type of \tcode{wchar_t}}
4333+
signed or unsigned integer type as its underlying type.
4334+
The values of type \tcode{wchar_t} can represent
4335+
distinct codes for all members of the largest extended character set
4336+
specified among the supported locales\iref{locale}.
42924337
\indextext{\idxcode{char16_t}|see{type, \tcode{char16_t}}}%
42934338
\indextext{\idxcode{char32_t}|see{type, \tcode{char32_t}}}%
4294-
\indextext{\idxcode{wchar_t}|see{type, \tcode{wchar_t}}}%
42954339
\indextext{type!\idxcode{char16_t}}%
42964340
\indextext{type!\idxcode{char32_t}}%
4297-
\indextext{type!\idxcode{wchar_t}}%
4298-
\indextext{underlying type|see{type, underlying}}%
42994341
\indextext{type!underlying!\idxcode{char16_t}}%
43004342
\indextext{type!underlying!\idxcode{char32_t}}%
4301-
Type \tcode{wchar_t} is a distinct type whose values can represent
4302-
distinct codes for all members of the largest extended character set
4303-
specified among the supported locales\iref{locale}. Type
4304-
\tcode{wchar_t} shall have the same size, signedness, and alignment
4305-
requirements\iref{basic.align} as one of the other integral types,
4306-
called its \defnx{underlying type}{type!underlying!\idxcode{wchar_t}}. Types \tcode{char16_t} and
4307-
\tcode{char32_t} denote distinct types with the same size, signedness,
4308-
and alignment as \tcode{uint_least16_t} and \tcode{uint_least32_t},
4309-
respectively, in \tcode{<cstdint>}, called the underlying types.
4343+
Types \tcode{char16_t} and \tcode{char32_t} denote distinct types
4344+
whose underlying types are \tcode{uint_least16_t} and \tcode{uint_least32_t},
4345+
respectively, in \tcode{<cstdint>}.
43104346

43114347
\pnum
43124348
\indextext{Boolean type}%
4313-
Values of type \tcode{bool} are either \tcode{true} or
4314-
\tcode{false}.\footnote{Using a \tcode{bool} value in ways described by this document
4315-
as ``undefined'', such as by examining the value of an
4316-
uninitialized automatic object, might cause it to behave as if it is
4317-
neither \tcode{true} nor \tcode{false}.}
4318-
\begin{note} There are no \tcode{signed}, \tcode{unsigned}, \tcode{short},
4319-
or \tcode{long bool} types or values. \end{note} Values of type
4320-
\tcode{bool} participate in integral promotions\iref{conv.prom}.
4349+
\indextext{type!Boolean}%
4350+
Type \tcode{bool} is a distinct type that has
4351+
the same object representation,
4352+
value representation, and
4353+
alignment requirements as
4354+
an \impldef{underlying type of \tcode{bool}} unsigned integer type.
4355+
The values of type \tcode{bool} are
4356+
\tcode{true} and \tcode{false}.\footnote{Using a \tcode{bool} value
4357+
in ways described by this document as ``undefined'',
4358+
such as by examining the value of an uninitialized automatic object,
4359+
might cause it to behave as if it is neither \tcode{true} nor \tcode{false}.}
4360+
\begin{note}
4361+
There are no \tcode{signed}, \tcode{unsigned},
4362+
\tcode{short}, or \tcode{long bool} types or values.
4363+
\end{note}
43214364

43224365
\pnum
4366+
\indextext{type!integral}%
43234367
Types \tcode{bool}, \tcode{char}, \tcode{char16_t}, \tcode{char32_t},
43244368
\tcode{wchar_t}, and the signed and unsigned integer types are
43254369
collectively called
4326-
\defnx{integral}{integral type} types.\footnote{Therefore, enumerations\iref{dcl.enum} are not integral; however,
4327-
enumerations can be promoted to integral types as specified
4328-
in~\ref{conv.prom}.}
4329-
A synonym for integral type is
4330-
\indextext{signed integer representation!ones' complement}%
4331-
\indextext{signed integer representation!two's complement}%
4332-
\indextext{signed integer representation!signed magnitude}%
4333-
\defn{integer type}. The representations of integral types shall
4334-
define values by use of a pure binary numeration system.\footnote{A positional
4335-
representation for integers that uses the binary digits 0
4336-
and 1, in which the values represented by successive bits are additive,
4337-
begin with 1, and are multiplied by successive integral power of 2,
4338-
except perhaps for the bit with the highest position. (Adapted from the
4339-
\doccite{American National Dictionary for Information Processing Systems}.)}
4340-
\begin{example} This document permits two's complement,
4341-
ones' complement and signed magnitude representations for integral types.
4342-
\end{example}
4370+
\defnx{integral types}{integral type}.
4371+
A synonym for integral type is \defn{integer type}.
4372+
\begin{note}
4373+
Enumerations\iref{dcl.enum} are not integral;
4374+
however, unscoped enumerations can be promoted to integral types
4375+
as specified in \ref{conv.prom}.
4376+
\end{note}
43434377

43444378
\pnum
4379+
\indextext{floating-point type|see{type, floating-point}}%
43454380
There are three \defnx{floating-point types}{type!floating-point}:
43464381
\indextext{type!\idxcode{float}}%
43474382
\tcode{float},

0 commit comments

Comments
 (0)