Potential problem with negative minimum
#2
Closed
opened 4 years ago by EnilPajic
·
2 comments
Loading…
Reference in New Issue
There is no content yet.
Delete Branch '%!s(<nil>)'
Deleting a branch is permanent. It CANNOT be undone. Continue?
Hello. First of all, good work here!
The code
N < 0 ? -N : N
could be problematic in some cases ifN
is minimum value. E.g if signed integrals are defined as two's complement, then forsigned char
range may be -128 to 127, and problem with-N
is whenN = -128
(+128 may be not valid forsigned char
).I've created PR to fix this.
Hi, thanks for reporting this issue! I've checked out your proposed fix, and while it is addressing this issue, it appears to be breaking the conversion of other negative numbers. I'm starting to check out fixes for this issue too; do let me know if you make more progress.
I've found the issue: looks like the
base
template parameter beingunsigned int
breaks the negative arithmetic. Can fix that just by switchingbase
toint
.I'm new to working with pull requests/issues, but I'm going to try and make that edit to your PR. If that works, I'll merge it in and resolve this issue.
Edit: Was able to make the edit and merge the PR. All looks good!