any C standard since forever has stated clearly that the behaviour is undefined. i've never written a program that mods a negative number. have fun in portability.
brucee On 12/16/05, Dan Cross <[EMAIL PROTECTED]> wrote: > On Thu, Dec 15, 2005 at 10:53:06PM -0600, erik quanstrom wrote: > > | Please note that this definition of DIV and MOD differs from the > > | definition given in [M. Reiser, N. Wirth. Programming in Oberon. p. > > | 36]: > > | x = (x DIV y) * y + (x MOD y), and > > | 0 <= (x MOD y) < y > ^^^^^^^^^^^^^^^^^^ > > | > > | So, what *is* -5 MOD 3? > > | > > > > -2 > > Are you sure? It looks to me more than it'd be +1. Wirth's definition > above would tend to indicate that x MOD y is always positive, unless I'm > reading it wrong, or that's not the whole story (and I confess I'm too > lazy to look up the definitions in context). If I'm right, that would > also imply that x DIV y tends more wards negative infinity than zero > for negative numerators. > > - Dan C. > >
