Boost logo

Boost :

From: John Maddock (john_at_[hidden])
Date: 2006-08-02 11:53:12

Paul A Bristow wrote:
> Does anyone have a ***portable*** version of macro signbit (C99)

Not quite, but I recently added a rather brain dead version to the
Math-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.


Boost list run by bdawes at, gregod at, cpdaniel at, john at