Negative integer div, Was: Something IBM did right (RT division of negatives).
Bjorn Engsig
bengsig at orcenl.uucp
Tue Nov 8 23:43:02 AEST 1988
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"
More information about the Comp.lang.c
mailing list