On Tue, May 19, 2009 at 02:06:37PM +0200, Jean-Denis Muys wrote:
> 
> There exists unique natural numbers q and r such as:
> 
> a = b*q+r
> 0 <= r < b
> 
> q is defined as the quotient, r is defined as the remainder.
> 
> So if the % operator wants to match that math definition, its results should
> never be negative. In the example given, (-1)%7 should therefore be 6.

It depends wether you focus on a arithmetic meaning of the remainder or
on what you call "mathematics" (what would be "Restklasse" in german, I
don't know the english term).

In terms of "Restklasse" you want a positive modulo and get a negative
division result.

In terms of arithmetics you want a positive division result and get a
negative modulo.

Both are valid solutions. At the end you have to live with the
definition of the given implementation.

Just check the sign and correct the sign of the result according to your
needs.
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to