Skip to content

Commit

Permalink
Merge pull request #61 from kokkos/issue-60
Browse files Browse the repository at this point in the history
Fix issue #60 
Everybody seems gone, I just override the review and merge in since that should fix the last failure on the Jenkins jobs for tonight.
  • Loading branch information
crtrott authored Aug 30, 2017
2 parents eac03f0 + aa940d4 commit 01dad6d
Showing 1 changed file with 29 additions and 4 deletions.
33 changes: 29 additions & 4 deletions src/Kokkos_ArithTraits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,33 @@ intPowImpl (const IntType x, const IntType y)
}


// Warning free abs function for types where we don't know whether they are signed (like char)
template<class T, bool is_signed = std::numeric_limits<T>::is_signed >
struct integer_abs {
static
KOKKOS_INLINE_FUNCTION
T abs(const T& val);
};

template<class T>
struct integer_abs<T,true> {
static
KOKKOS_INLINE_FUNCTION
T abs(const T& x) {
return x<0? -x:x;
}
};

template<class T>
struct integer_abs<T,false> {
static
KOKKOS_INLINE_FUNCTION
T abs(const T& x) {
return x;
}
};



/// \fn intPowSigned
/// \tparam IntType A built-in signed integer type.
Expand Down Expand Up @@ -1471,10 +1498,8 @@ class ArithTraits<char> {
return false;
}
static KOKKOS_FORCEINLINE_FUNCTION mag_type abs (const val_type x) {
// This may trigger a compiler warning if char is unsigned. On
// all platforms I have encountered, char is signed, but the C(++)
// standard does not require this.
return x >= 0 ? x : -x;
// This avoids warnings based on whether char is signed or unsigned
return integer_abs<char>::abs(x);
}
static KOKKOS_FORCEINLINE_FUNCTION val_type zero () {
return 0;
Expand Down

0 comments on commit 01dad6d

Please sign in to comment.