Skip to content

Commit

Permalink
Rewrite ABSi64 to avoid a Visual Studio warning.
Browse files Browse the repository at this point in the history
  - negating unsigned integers is one of the few well defined operations in C...
  • Loading branch information
skrah committed Jan 8, 2018
1 parent da8caef commit 9423906
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions libndtypes/overflow.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,11 @@ MULi64(int64_t a, int64_t b, bool *overflow)
static inline int64_t
ABSi64(int64_t a, bool *overflow)
{
int64_t b = a >= 0 ? a : (int64_t)(-((uint64_t)a));
*overflow |= a == INT64_MIN;
return b;
if (a == INT64_MIN) {
*overflow = 1;
return INT64_MIN;
}
return a >= 0 ? a : -a;
}

static inline uint16_t
Expand Down Expand Up @@ -106,9 +108,11 @@ MULi64(int64_t a, int64_t b, bool *overflow)
static inline int64_t
ABSi64(int64_t a, bool *overflow)
{
int64_t b = a >= 0 ? a : (int64_t)(-((uint64_t)a));
*overflow |= a == INT64_MIN;
return b;
if (a == INT64_MIN) {
*overflow = 1;
return INT64_MIN;
}
return a >= 0 ? a : -a;
}

static inline uint16_t
Expand Down

0 comments on commit 9423906

Please sign in to comment.