C's 'mod' isn't really mod. It's actually remainder. It's always been this way to my knowledge. If you want a real "mod" use Python or Ada :) Dave On 12/15/05, Jack Johnson wrote: > > Not really, but all the talk about Singularity got me poking around > and I came across this: > > ------ > > How are the functions DIV and MOD defined? > > The following answers are given by the Internal Working Document on > the Common Language Infrastructure (CLI). > > result = value1 DIV value2 satisfies the following conditions: > |result| = |value1| / |value2|, and > sign(result) = +, if sign(value1) = sign(value2) > sign(result) = - , if sign(value1) # sign(value2) > > result = value1 MOD value2 satisfies the following conditions: > result = value1 - value2 * (value1 DIV value2), and > 0 <= |result| < |value2|, and > sign(result) = sign(value1) > > 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 > > ( from http://www.bluebottle.ethz.ch/oberon.net/faq.html#ad_DivMod ) > > ------ > > I kind of collect random, older computer science texts, so I cracked > open The Nature of Computation by Pohl and Shaw, which yields: > > "x MOD y = x - (x ÷ y) * y, where ÷ indicates integer division (i.e. > fractions are disregarded; equivalently, the result of the division is > truncated)." > > So, what *is* -5 MOD 3? > > -Jack >