comp.lang.c
[Top] [All Lists]

Re: More bit shifting issues

Subject: Re: More bit shifting issues
From: Andrey Tarasevich
Date: Tue, 01 Apr 2008 12:47:29 -0700
Newsgroups: comp.lang.c


Boltar wrote:
...
Thats what I would have expected. Its a shift , not a mathematic
operation, the sign should be irrelevant and the value should just be
treated as 32 seperate bits to be moved as appropriate. Why would
anyone design this operation to preserve the sign? I don't understand.
...

In C89/90 it is recommended (and in C99 it is required) that the integral division '/' rounds its results towards '0'. In many cases it is useful to have a modulo-correct version of integral division operator, i.e. operator that always rounds towards negative infinity. This is what sign-preserving shift does for power-of-2 division on 2's complement platforms.

(Doesn't look like much of a rationale, but for what it's worth...)

Of course, since the behavior is implementation-defined, one cannot rely on this behavior as being portable.

--
Best regards,
Andrey Tarasevich

<Prev in Thread] Current Thread [Next in Thread>
Privacy Policy