Use signbit for floating point sign<T>
This commit is contained in:
parent
610ca2d46d
commit
4a745f870e
25
maths.cpp
25
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 <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);
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user