C on non-binary machines [was Re: Structured Fortran - was Re: ...]
Mouse
mouse at Rodents-Montreal.ORG
Wed Sep 23 10:15:44 CDT 2015
> As far as I can remember, the C standard still do not require that
> the computer uses two complement.
No, but unsigned integer types have to work as if it did. Signed
integer types may use two's complement, one's complement, or even
sign/magnitude, but nothing else; for example, implementing signed
integers with base -2 is not permitted. 6.2.6.2 in the very late C99
draft I have, notes manually edited in:
[#2] For signed integer types, the bits of the object
representation shall be divided into three groups: value
bits, padding bits, and the sign bit. There need not be any
padding bits; there shall be exactly one sign bit. Each bit
that is a value bit shall have the same value as the same
bit in the object representation of the corresponding
unsigned type (if there are M value bits in the signed type
and N in the unsigned type, then M<=N). If the sign bit is
zero, it shall not affect the resulting value. If the sign
bit is one, 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);
(that's -(2^N), mangled by textification)
-- the sign bit has the value -(2N-1) (one's complement).
(that's -((2^N)-1), mangled by textification)
Which of these applies is implementation-defined, as is
whether the value with sign bit 1 and all value bits zero
(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.
...
[#5] The values of any padding bits are unspecified.45) A
(the "45)" is a footnote reference)
valid (non-trap) object representation of a signed integer
type where the sign bit is zero is a valid object
representation of the corresponding unsigned type, and shall
represent the same value.
/~\ The ASCII Mouse
\ / Ribbon Campaign
X Against HTML mouse at rodents-montreal.org
/ \ Email! 7D C8 61 52 5D E7 2D 39 4E F1 31 3E E8 B3 27 4B
More information about the cctech
mailing list