Potential problem with negative minimum #2

Closed
opened 4 years ago by EnilPajic · 2 comments
EnilPajic commented 4 years ago (Migrated from github.com)

Hello. First of all, good work here!

The code N < 0 ? -N : N could be problematic in some cases if N is minimum value. E.g if signed integrals are defined as two's complement, then for signed char range may be -128 to 127, and problem with -N is when N = -128 (+128 may be not valid for signed char).

I've created PR to fix this.

Hello. First of all, good work here! The code `N < 0 ? -N : N` could be problematic in some cases if `N` is minimum value. E.g if signed integrals are defined as two's complement, then for `signed char` range may be -128 to 127, and problem with `-N` is when `N = -128` (+128 may be not valid for `signed char`). I've created [PR](https://github.com/tcsullivan/constexpr-to-string/pull/1) to fix this.
tcsullivan commented 4 years ago (Migrated from github.com)

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.

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.
tcsullivan commented 4 years ago (Migrated from github.com)

I've found the issue: looks like the base template parameter being unsigned int breaks the negative arithmetic. Can fix that just by switching base to int.

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!

I've found the issue: looks like the `base` template parameter being `unsigned int` breaks the negative arithmetic. Can fix that just by switching `base` to `int`. 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!
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: clyne/constexpr-to-string#2
Loading…
There is no content yet.