I wrote:> As a mathematician I have often found the behaviour of div and mod> operators a little annoying (at least in C, Pascal etc). Number> theorists universally use the following standard definition of integer> division:

Of course, what I meant to say was 0 <= r <= |d|-1. Thanks to
William for prompting me to spot this error.

While I have the chance, I should apologise for a slightly premature
posting. I had not really considered the possibility of negative d
in detail. In the context I had in mind, number theory is not
concerned with negative values of d. However, I stand by my
original post, at least when d is positive. I would propose

1 n = qd + r
2 0 <= r <= d-1 when d>0
3 0 >= r >= -d+1 when d<0

1 and 2 make the mod operator behave in a manner which I consider to
be consistent with the theory. 3 'reflects' the arithemtic
through 0 when the sign of d reverses. This is an aesthetic
decision.

However, some may object to 2 on the grounds that the heuristics

(-n) mod d = n mod (-d) = -(n mod d)

are then not satisfied. I would stress through that there is no
reason to expect these to hold. [The integers do not form a field
under the usual arithmetic operations].