Constraints on UINT_MAX (was Re: # to the nth power)
Martin Weitzel
martin at mwtech.UUCP
Thu Nov 15 02:55:37 AEST 1990
In article <14379 at smoke.brl.mil> gwyn at smoke.brl.mil (Doug Gwyn) writes:
>In article <ENAG.90Nov3145415 at hild.ifi.uio.no> enag at ifi.uio.no (Erik Naggum) writes:
>-In article <1990Nov2.182217.13958 at NCoast.ORG> catfood at NCoast.ORG (Mark W. Schumann) writes:
>- Spiffy, but it does depend on (exponent & 1) being the same as saying
>- "exponent is odd." Most implementations support this, though.
>
>That's good, because the C standard requires this, for positive integers.
What about ((unsigned) exponent & 1) ?
As I read the ANSI-Standard, in case of a negative exponent,
`(unsigned) exponent' yields the value `UINT_MAX + exponent + 1'.
Now: I've found no explicit guarantee in the standard about the value
of UINT_MAX, other than its minimum is 65535. It would seem logical to
me that the `pure binary representation' also enforces that UINT_MAX
is allways one less than a power of two, which in turn would mean it
is always odd, which would make `(unsigned) exponent & 1' a working
substitute for `exponent % 2' for all values of exponent.
On the other hand, could some hypothetical architecture reserve certain
bit-patterns in an unsigned for special use, and make my above assumption
about the value of UINT_MAX invalid?
Are there other constraints in the standard, which, may be indirectly,
still require constraints on UINT_MAX? Is there anything in the standard
that rules out an implementation with an UINT_MAX of, say, 87944?
For example: The Bit-Shift Operator doesn't mention the possibility that
shifting some bit pattern may result in illegal values. Furthermore it
guarantees for left shift of an unsigned operand the equivalence to
multiplication by powers of two. For multiplication of unsigned the
overflow problem is well defined (result modulo UINT_MAX + 1). With an
UINT_MAX of 87944 not all the above could hold true.
There are two assumptions I'm not sure of:
a) Can the shift operator be applied to *any* arbitrary bit pattern,
resulting in a new pattern according to all the defined semantics,
b) Can the above proof for a special case (87944) be generalized to
all numbers for UINT_MAX, which don't have the propert? 2**N - 1
(with integral N)?
--
Martin Weitzel, email: martin at mwtech.UUCP, voice: 49-(0)6151-6 56 83
More information about the Comp.lang.c
mailing list