Jan Karel Schreuder
jan9447 at me.com
Mon Oct 8 02:13:14 CEST 2012
On Oct 7, 2012, at 8:06 PM, Dave Angel <d at davea.name> wrote:
> On 10/07/2012 08:00 PM, Jan Karel Schreuder wrote:
>> On Oct 7, 2012, at 7:24 PM, Dave Angel <d at davea.name> wrote:
>>> It still makes no sense to me. There are at least two equally silly
>>> ways to define the results of a negative modulus, and you've properly
>>> described one of them, presumably the one that Python implements.
>>> But I've used and abused about 35 languages over the years, and each
>>> makes its own choice for this. I'd rather just call it undefined, and
>>> eliminate it. That's what we did when the hardware guys couldn't decide
>>> how the hardware was going to respond to a particular microcode bit
>>> pattern. They documented it as undefined, and I made it illegal in the
>>> microcode assembler.
>>> Fortunately, the OP isn't asking about this case, which is the other
>>> reason I didn't bother to describe what Python does.
>>> I'm not a professional programmer, so I might be way off base here. But what I like about Pythons modulo solution is that I can use it to right and left shift in lists or tuples, and I will link to the first element when I right shift past the last element and link to the last element when I left shift past the first element. In other words I can consider the last as a chain where the last and the first element are connected. This I find useful in surprisingly many situations.
> Certainly, but you've never had to do that with lists or tuples having
> negative lengths. It's a negative modulus that I'm complaining about.
Aha. Yes I was talking about the solution to -3%5 and found the python solution (2) useful. I'm agnostic about x% -5
More information about the Tutor