From: Luke Kenneth Casson Leighton Date: Thu, 9 Jul 2020 12:28:42 +0000 (+0100) Subject: whoops trunc_div returning neg/neg result rather than abs/abs X-Git-Tag: 24jan2021_ls180~41 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=923551b7924eb256fcf61cafda4ca78ccf03784f;p=nmutil.git whoops trunc_div returning neg/neg result rather than abs/abs --- 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