From: Johan Råde (rade_at_[hidden])
Date: 2006-08-04 06:02:02
John Maddock wrote:
> Johan Råde wrote:
>> This can be templatized, and will handle such things as 80-bit long
> Maybe, don't forget the padding bytes that are often injected into such
> types (only an issue if the endianness put's the sign bit at the end of the
> 10-byte sequence rather than the beginning).
> Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
I think the following is a reasonable compromise:
const boost::uint32_t signbit_mask
inline bool signbit_impl(float x)
return binary_cast<boost::uint32_t>(x) & signbit_mask;
inline bool signbit_impl(double x)
inline bool signbit_impl(long double x)
Here I assume that
1. IEEE 754 or some similar representation
2. sizeof(float) == 4
3. casts between different numeric types preserve the sign bits, also
for non-finite numbers.
That should cover a large number of platforms.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk