
March 18, 2022
1:59 p.m.
On Sat, 19 Mar 2022 at 07:16, Ben Rudiak-Gould <benrudiak@gmail.com> wrote:
On Fri, Mar 18, 2022 at 8:31 AM Chris Angelico <rosuav@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