|
Boost : |
From: Johan Råde (rade_at_[hidden])
Date: 2006-08-02 14:09:11
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
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk