Boost logo

Boost :

From: John Maddock (john_at_[hidden])
Date: 2006-08-03 06:35:19


Gennaro Prota wrote:
> TR1 asks for a non-macro version:
>
> template<class T> bool signbit(T x);
>
> Like its C99 counterpart (which formally yields an int, but the
> behavior is bool-like: nonzero iff the argument value has negative
> sign) it shall work for any floating point value, including, if
> supported, signed zeros, infinities and NaNs. I didn't try but I guess
> the only slightly tricky point to watch for is signaling NaNs.

And the endianness of the float's if you're doing bit testing. But of
course if there is a macro already it's easy enough to convert it into a
function.

> Note that all this is quite different, in scope and semantics, from
> your sign facility, which BTW could perhaps be "extended" to:
>
> template <class T>
> int sign(const T& v)
> { return v < 0 ? -1 : (v > 0 ? 1 : 0) }

I know, but I'm not sure about it :-) Or at least it complicates the uses I
had for it, maybe I'll demote it to a detail...

John.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk