Use signbit for floating point sign<T>

This commit is contained in:
Danny Robson 2012-05-03 15:55:45 +10:00
parent 610ca2d46d
commit 4a745f870e
2 changed files with 27 additions and 4 deletions

View File

@ -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 <typename T>
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);

View File

@ -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 <typename T>
int sign (T val);
#endif // __MATHS_HPP