Re: remainder of dividing by zero
Ethan Furman wrote: Okay, so I haven't asked a stupid question in a long time and I'm suffering withdrawal symptoms... ;) 5 % 0 = ? It seems to me that the answer should be 5: no matter how many times we add 0 to itself, the remainder of the intermediate step will be 5. Is there a postulate or by definition answer as to why this should not be so? ~Ethan~ Considering the mathématical definition of integer division, a = bq +r, (q, r) is unique. With your definition, there is an infinite number of solutions fo q. You could successfully argue that for r, only 1 solution is possible. The french wiki page on modulo suggests some language choosed to do so without listing those languages. If you consider bool(5) returning True in Python, it makes no sense, but it's really convinient and used by everyone (practicality beats purity ?) JM -- http://mail.python.org/mailman/listinfo/python-list
Re: remainder of dividing by zero
Ethan Furman wrote: Okay, so I haven't asked a stupid question in a long time and I'm suffering withdrawal symptoms... ;) 5 % 0 = ? Thanks for your replies, much appreciated. ~Ethan~ -- http://mail.python.org/mailman/listinfo/python-list
remainder of dividing by zero
Okay, so I haven't asked a stupid question in a long time and I'm suffering withdrawal symptoms... ;) 5 % 0 = ? It seems to me that the answer should be 5: no matter how many times we add 0 to itself, the remainder of the intermediate step will be 5. Is there a postulate or by definition answer as to why this should not be so? ~Ethan~ -- http://mail.python.org/mailman/listinfo/python-list
Re: remainder of dividing by zero
On 4/12/2012 6:34 PM, Ethan Furman wrote: Okay, so I haven't asked a stupid question in a long time and I'm suffering withdrawal symptoms... ;) 5 % 0 = ? It seems to me that the answer should be 5: no matter how many times we add 0 to itself, the remainder of the intermediate step will be 5. Is there a postulate or by definition answer as to why this should not be so? 0 = M % N N no solution for N == 0 m // n, m % n = divmod(m, n), which is to say, divmod is the fundamental recursively defined operation and // and % are each one of the components with the other ignored. m % n = divmod(m, n)[1] and divmod is not defined for n == 0 def divmod(m, n): # m, n not negative q, r = 0, m while m = n: q, r = q+1, r-n return q, r Of course, given m, n in base n representation, the way you learned to do it in school is faster. In binary, it is even easier because each digit is 0 or 1 so no guessing needed as with base 10. -- Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
Re: remainder of dividing by zero
On 12/04/2012 23:34, Ethan Furman wrote: Okay, so I haven't asked a stupid question in a long time and I'm suffering withdrawal symptoms... ;) 5 % 0 = ? It seems to me that the answer should be 5: no matter how many times we add 0 to itself, the remainder of the intermediate step will be 5. Is there a postulate or by definition answer as to why this should not be so? If x 0, 0 = 5 % x x. At the limit of x == 0, you get 0 = 5 % 0 0. At that point, an exception is probably a good idea! :-) -- http://mail.python.org/mailman/listinfo/python-list