diff --git a/maths.cpp b/maths.cpp index 976827b5..3c2aef59 100644 --- a/maths.cpp +++ b/maths.cpp @@ -109,3 +109,28 @@ template uint8_t round_pow2 (uint8_t); template uint16_t round_pow2 (uint16_t); template uint32_t round_pow2 (uint32_t); template uint64_t round_pow2 (uint64_t); + + +template +int +sign (T val) { + return val >= 0 ? 1 : -1; +} + + +template <> +int +sign (float val) { + return copysign (1.0, val); +} + + +template <> +int +sign (double val) { + return copysign (1.0, val); +} + + +template int sign (int); + diff --git a/maths.hpp b/maths.hpp index cb439066..e2fd2835 100644 --- a/maths.hpp +++ b/maths.hpp @@ -145,9 +145,7 @@ max (const T &a , const T &b , const Args &...args ) { return max ( b > a ? b : a, args...); } -inline double sign (double x) { return x >= 0 ? 1.0 : -1.0; } -inline float sign (float x) { return x >= 0 ? 1.0 : -1.0; } -inline int sign (int x) { return x >= 0 ? 1 : -1 ; } - +template +int sign (T val); #endif // __MATHS_HPP