diff options
author | Sven Göthel <[email protected]> | 2024-05-10 09:48:59 +0200 |
---|---|---|
committer | Sven Göthel <[email protected]> | 2024-05-10 09:48:59 +0200 |
commit | eaa2aafd020dda4d9cf4051bcfd63e523547e784 (patch) | |
tree | 1091a4632ce1f8304695c5b30ba0ccb0e118b61a /include/jau | |
parent | 3e2a6eb1b5c6ea9b925ec3b4ffe02881078b6460 (diff) |
base_math: Add sign() for unsigned<T>
Diffstat (limited to 'include/jau')
-rw-r--r-- | include/jau/base_math.hpp | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/include/jau/base_math.hpp b/include/jau/base_math.hpp index 84a38b2..29be3f8 100644 --- a/include/jau/base_math.hpp +++ b/include/jau/base_math.hpp @@ -79,11 +79,20 @@ namespace jau { * @return function result */ template <typename T, - std::enable_if_t< std::is_arithmetic_v<T>, bool> = true> + std::enable_if_t< std::is_arithmetic_v<T> && + !std::is_unsigned_v<T>, bool> = true> constexpr int sign(const T x) noexcept { return (int) ( (T(0) < x) - (x < T(0)) ); } + + template <typename T, + std::enable_if_t< std::is_arithmetic_v<T> && + std::is_unsigned_v<T>, bool> = true> + constexpr int sign(const T x) noexcept + { + return (int) ( T(0) < x ); + } /** * Safely inverts the sign of an arithmetic number w/ branching in O(1) |