JTC1/SC22/WG14
N725
ISO/IEC JTC1/SC22/WG14 N725
Simplified integer conversion rules
Clive D.W. Feather
Abstract
========
The rules for conversion of integers in 6.2.1.2 make use of the word
"size", which is known to be a problem, and cannot be fixed just by
using the term "precision". Luckily it is not necessary to jump through
hoops - there is a simpler way of presenting things.
Proposal
========
Replace 6.2.1.2 with the following.
6.2.1.2 Signed and unsigned integers
When a value with integer type is converted to another integer
type, if the value can be represented by the new type, it is
unchanged.
Otherwise, if the destination type is unsigned, the value is
converted by repeatedly adding or subtracting one more than the
maximum value that can be represented in the destination type
until the value is in the range of the destination type.
Otherwise the destination type is signed and the value cannot
be represented in it; the result is implementation-defined.
[[Due to the major changes made in this area of the Standard, this paper
was passed to an Editorial Review Board for final wording.]]