On 5/19/09 1:57 PM, "Igor Tandetnik" <itandet...@mvps.org> wrote:

> "John Machin" <sjmac...@lexicon.net> wrote
> in message news:4a129cb4.2090...@lexicon.net
>> It's handy for checking how things work e.g.
>> 
>> sqlite> select (-1) % 7;
>> -1
>> sqlite> -- it's not a real modulo operator :-(
> 
> What do you feel is wrong with this result? What should a "real" modulo
> operator return, in your opinion? Before you answer, note that you very
> likely want this equality to hold for all a, b!=0 :
> 
> a = q*b + r
> where q = a/b, r = a%b
> 
> Igor Tanetnik 
> 

My math courses taught me a long time ago, that the remainder r in Euclidian
division of a by b is defined by:

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.

But I will not argue that the % operator needs to match the math definition,
though I would probably prefer it to.

Jean-Denis

_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to