projects
/
nmutil.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
b639fbc
)
add overflow detection to DIVS
author
Jacob Lifshay
<programmerjake@gmail.com>
Wed, 7 Oct 2020 02:36:11 +0000
(19:36 -0700)
committer
Jacob Lifshay
<programmerjake@gmail.com>
Wed, 7 Oct 2020 02:36:11 +0000
(19:36 -0700)
overflow shouldn't occur when calling DIVS since it should have been
detected in the code calling DIVS to properly handle edge cases.
src/nmutil/divmod.py
patch
|
blob
|
history
diff --git
a/src/nmutil/divmod.py
b/src/nmutil/divmod.py
index af5d2141a58e00b27e4b2ad62a860b478cda50d5..357fdcb2d905f31492ad961d94578bc73d1f83dd 100644
(file)
--- a/
src/nmutil/divmod.py
+++ b/
src/nmutil/divmod.py
@@
-17,6
+17,9
@@
def trunc_divs(n, d):
res = copy(n)
if (sign_n == sign_d):
res.value = abs_q
+ if res.value & (1 << (res.bits - 1)) != 0:
+ # result should be positive but is negative
+ raise OverflowError()
return res
mask = (1 << res.bits) - 1
res.value = (-abs_q) & mask