[comp.lang.c] Negative integer div, Was: Something IBM did right

bengsig@orcenl.uucp (Bjorn Engsig) (11/08/88)

The first edition of K&R (sorry I don't have the second) clearly says
that "... the form of truncation is machine-dependent if either operand
is negative."

So: Many of us have a feeling of what i/j or i%j should be for negative
i and/or j, but the compiler may do whatever is available on the machine
as long as (i/j)*j + i%j == i (when b != 0).

There is also no strict definition of i>>j for negative i.  If i is unsigned,
i>>j is a logical shift, if i is not unsingned, i>>j  M A Y  be arithmetic.
-- 
Bjorn Engsig, ORACLE Europe      \ /    "Hofstaedter's Law:  It always takes
 ..!uunet!mcvax!orcenl!bengsig    X      longer than you expect, even if you
phone:  +31 21 59 56 411         / \     take into account Hofstaedter's Law"