On Sat, 19 Mar 2022 at 07:16, Ben Rudiak-Gould <benrud...@gmail.com> wrote: > > On Fri, Mar 18, 2022 at 8:31 AM Chris Angelico <ros...@gmail.com> wrote: >> >> if y < 0: return -(x // -y), x % y > > > I think that should be > > if y < 0: return -(x // -y), x % -y >
Hmm. According to Wikipedia [1] the result of divmod(7,-3) should be (-2, 1) and divmod(-7, -3) should be (3, 2). So yes, looks like I messed it up. In any case, it would need some proper unit tests to make sure it's mathematically correct, but it'll be this simple whichever way it is. ChrisA [1] https://en.wikipedia.org/wiki/Euclidean_division#Examples _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/XXJRYHEPO5SK4HCAKUO3LMHAM4LWFPIC/ Code of Conduct: http://python.org/psf/codeofconduct/