[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [gnugo-devel] sign bit bit shift issue

From: Hellwig Geisse
Subject: RE: [gnugo-devel] sign bit bit shift issue
Date: Sat, 08 Feb 2003 16:11:35 +0100 (CET)

On 08-Feb-03 Arend Bayer wrote:
> According to the C standard, the patch below fixes a bug. Rotating into
> the sign bit of a signed integer is undefined.
> Does anyone happen to know whether this is a problem in real world?
> (I.e. do there exist platforms where (1 << 31 == 0x8000000) does not
> hold true?)
> Arend

I quote from Kernighan & Ritchie, The C Programming Language,
Second Edition (ANSI C), A7.8 (page 206):

"The value of E1<<E2 is E1 (interpreted as a bit pattern) left-shifted
E2 bits; in the absence of overflow, this is equivalent to multiplication
by 2^E2. The value of E1>>E2 is E1 right-shifted E2 bit positions. The
right shift is equivalent to division by 2^E2 if E1 is unsigned or if it
has a non-negative value; otherwise the result is implementation-defined."

So according to this text (which admittedly isn't the standard) the only
problem seems to be a right-shift, done with a signed integral type which
has a negative value. This of course relates to the implementation of right
shifts with or without sign extension, which is left to the implementor.

Arend, did you find this in the standards document? I never heard of
problems shifting INTO the sign bit.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]