
2 Aug
2006
2 Aug
'06
6:09 p.m.
John Maddock wrote: -Toolkit code, just a:
template <class T> int signbit(const T& v) { return v < 0 ? 1 : 0; }
To be honest that's not very useful :-(
What I do find more useful is:
template <class T> int sign(const T& v) { return v < 0 ? -1 : 1; }
which is invaluable when you need to compare the sign of two (or more) numbers but are concerned about numeric overflow/underflow in the usual a*b < 0 trick.
Will not handle negative zero and negative NaN. Will probably handle negative infinity. --Johan