diff options
Diffstat (limited to 'src/macros.h')
-rw-r--r-- | src/macros.h | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/src/macros.h b/src/macros.h index f42870f3c..e5f64c68f 100644 --- a/src/macros.h +++ b/src/macros.h @@ -79,6 +79,10 @@ template<typename T, typename U> static inline T AB(T& x, const uint8 s, const u #undef max #endif +#ifdef abs +#undef abs +#endif + /** * Returns the maximum of two values. * @@ -138,6 +142,18 @@ static inline uint minu(const uint a, const uint b) } /** + * Returns the absolute value of (scalar) variable. + * + * @note assumes variable to be signed + * @param a The value we want to unsign + * @return The unsigned value + */ +template <typename T> static inline T abs(T a) +{ + return (a < (T)0) ? -a : a; +} + +/** * Clamp an integer between an interval. * * This function returns a value which is between the given interval of @@ -519,8 +535,6 @@ static inline bool CHANCE16I(const uint a, const uint b, const uint32 r) for (_i = 0; _b != 0; _i++, _b >>= 1) \ if (_b & 1) -#define abs myabs - static inline uint16 ReadLE16Aligned(const void* x) { |