From 923551b7924eb256fcf61cafda4ca78ccf03784f Mon Sep 17 00:00:00 2001 From: Luke Kenneth Casson Leighton Date: Thu, 9 Jul 2020 13:28:42 +0100 Subject: [PATCH] whoops trunc_div returning neg/neg result rather than abs/abs --- src/nmutil/divmod.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/nmutil/divmod.py b/src/nmutil/divmod.py index 2dc3196..0f1a549 100644 --- a/src/nmutil/divmod.py +++ b/src/nmutil/divmod.py @@ -3,8 +3,11 @@ def trunc_div(n, d): abs_n = abs(n) abs_d = abs(d) - abs_q = n // d - if (n < 0) == (d < 0): + abs_q = abs_n // abs_d + #print ("trunc_div", n.value, d.value, + # abs_n.value, abs_d.value, abs_q.value, + # n == abs_n, d == abs_d) + if (n == abs_n) == (d == abs_d): return abs_q return -abs_q -- 2.30.2