Questions about srfi-77 Generic Arithmetic Bradley Lucier (05 Feb 2006 20:36 UTC)
Re: Questions about srfi-77 Generic Arithmetic Michael Sperber (10 Feb 2006 18:08 UTC)
div and mod. bear (22 Feb 2006 10:00 UTC)
Re: div and mod. Marcin 'Qrczak' Kowalczyk (19 Mar 2006 19:51 UTC)

div and mod. bear 22 Feb 2006 06:28 UTC

For what it's worth, here is the behavior that I as a programmer
expect from Div and Mod.

I expect mod always to return a number between zero inclusive and the
modulus exclusive.  IOW, for all real X:

(mod X 3) -> always a number between 0 and 3
(mod X -3) -> always a number between 0 and -3.

I expect div to return whatever has to be returned to assure that
for all real x and real N,

(+ (mod x N) (* (div x N) N)) -> x

It happens that in all cases where the signs match, the
expected sign of the result of div is positive or zero.  In
all cases where the signs don't match, the expected sign of
the result of div is negative or zero.

In many systems they behave otherwise.  When that happens, it
frequently causes bugs which I eventually trace down to the
application of div or modulus returning a negatve (or positive!)
number unexpectedly, and after some experimentation kluge
together a workaround or correction for.

				Bear